Given array of integers, remove each kth element from it.

Example

For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be

solution(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].

Input/Output

풀이

int[] solution(int[] inputArray, int k) {
    LinkedList <Integer> list = new LinkedList<>();
    int count = 0;
    
    for (int i = 0; i < inputArray.length; i ++) {
        count ++;
        if (count == k) count = 0;
         else list.add(inputArray[i]);
    }    
    
    int [] result = new int [list.size()];
    
    for (int i = 0; i < result.length; i ++) {
        result[i] = list.get(i);
    }
    
    return result;
}