/**
* squeeze() takes an array of ints. On completion the array contains the
* same numbers, but wherever the array had two or more consecutive
* duplicate numbers, they are replaced by one copy of the number. Hence,
* after squeeze() is done, no two consecutive numbers in the array are the
* same.
*
* Any unused elements at the end of the array are set to -1.
*
* For example, if the input array is [ 4 , 1 , 1 , 3 , 3 , 3 , 1 , 1 ], it
* reads [ 4 , 1 , 3 , 1 , -1 , -1 , -1 , -1 ] after squeeze() completes.
* @param ints
* the input array.
*/
public static void squeeze(int[] ints) {
// TODO: Fill in your solution here. Ours takes linear time and is less than 10 lines long,
// not counting blank/comment lines or lines already present in this file.
// ArrayList<Integer> k = new ArrayList<Integer>();
ниже - мой код, но по какой-то причине лог c неверен, он возвращает тот же массив, переданный в функцию, а не измененный, я считаю, что большинство лог c верны если нет ошибки в операторе продолжения. Каждый раз, когда в массиве появляется один и тот же последовательный индекс, его следует заменить этим одним индексом
int deleted = 0;
int i = 0;
for(int j = 1; j < ints.length; j++) { ?
if(ints[i] == ints[j]) {
deleted++;
continue;
}else {
//k.add(ints[i]);
i++;
}
}
ints = new int[ints.length + deleted];
for(int s = 0; s < ints.length; s++) {
if(ints[s] == 0) {
ints[s] = -1;
}
}
}
/**
* main() runs test cases on your squeeze() method. Prints summary
* information on basic operations and halts with an error (and a stack
* trace) if any of the tests fail.
*/