Leetcode 283. Move Zeroes

preview_player
Показать описание
Leetcode 283. Move Zeroes

My contact details

You can practice for coding interview from here

I am Mohammad Fraz , a final year Engineer at DTU and I create content for Coding and technical interviews for FAANG. I explain the intuition to solve Data Structure and Algorithm Questions from leetcode and other platforms. I also cover interview experiences for FAANG and other tech giants. You will also find lectures on the frequently asked interview questions.
Рекомендации по теме
Комментарии
Автор

What if the elements were not sorted like 1 3 12 what if they were 0, 3, 1, 0, 12 how do we sort them after

vansh
Автор

class Solution {
public void moveZeroes(int[] nums) {
int a[]=new int [nums.length];
int k=0, count=0;
for(int i=0;i<nums.length;i++)
{
if(nums[i]!=0){
// { System.out.print("99"+i+" ");
nums[k++]=nums[i];
}
else{
// System.out.print("*"+i+" ");
count++;

}
}
while(count!=0)
{
nums[nums.length-count]=0;
count--;
}
}
}

vaishnavirathore
Автор

how could we solve the follow-up part of this ques?

mohdsaadalikhan
Автор

else
{
nums[j]=0;
j++;
}
why this gives wrong answer

ankitkumarghosh