Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
Wow , awesome sir
Does while loop is necessary @ 05:26? Arrays by default initialize with zero's. May be while loop here causes performance.package arrays;import java.util.Arrays;public class MoveAllZerosToEnd { public static void main(String[] args) { int[] numbers = { -1, 0, -2, 0, -5, -7, 0, 0, 23, 32, -123 }; System.out.println(Arrays.toString(moveAllZerosToEnd(numbers))); } private static int[] moveAllZerosToEnd(int[] numbers) { int[] temp = new int[numbers.length]; int runningIndex = 0; for (int i = 0; i < numbers.length; i++) { if (numbers[i] != 0) { temp[runningIndex] = numbers[i]; runningIndex++; } } return temp; }}
Thankyou so much for you work
Great sir...
int j = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] != 0) { if (i != j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } j++; } }
Can you please do this using java 8
IntStream.of(nums).boxed().sorted(Comparator.comparing(n->n==0)).forEach(System.out::println);
👍👍
Wow , awesome sir
Does while loop is necessary @ 05:26? Arrays by default initialize with zero's. May be while loop here causes performance.
package arrays;
import java.util.Arrays;
public class MoveAllZerosToEnd {
public static void main(String[] args) {
int[] numbers = { -1, 0, -2, 0, -5, -7, 0, 0, 23, 32, -123 };
System.out.println(Arrays.toString(moveAllZerosToEnd(numbers)));
}
private static int[] moveAllZerosToEnd(int[] numbers) {
int[] temp = new int[numbers.length];
int runningIndex = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] != 0) {
temp[runningIndex] = numbers[i];
runningIndex++;
}
}
return temp;
}
}
Thankyou so much for you work
Great sir...
int j = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] != 0) {
if (i != j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
j++; }
}
Can you please do this using java 8
IntStream.of(nums).boxed().sorted(Comparator.comparing(n->n==0)).forEach(System.out::println);
👍👍