LeetCode Problem: 283. Move Zeroes || Java Solution Walkthrough

preview_player
Показать описание
LeetCode is a great platform for people who want general coding practice, whether that be for interviews or just wanting to practice their problem solving. I will be taking you through all the steps of finding the optimal solution to each problem on the site following a logical ordering setout by LeetCode themselves.

In this video, we are going over the problem 283. Move Zeroes, where the goal isto detect the zeros in the array, and shift them to the back while keeping the ordering of the non-zero numbers the same.

This problem requires us to modify the array in place, meaning we are not allowed to create a new array and simply place the elements back into that copied array. This will complicate things a little bit, but we can still technically complete this in O(n) but using two separate loops and a two counter values. One value to keep track of the index we are replacing, and one value to keep track of how many zeroes we need to add at the end. We can loop through once to count the number of zeros, and shift our non-zeros over, then loop through a second time to copy the zeroes onto the end of the array.

~~~ Stay Up To Date With My Social Media ~~~

#unknownkoder #leetcode #algorithms
Рекомендации по теме