- Joined
- Mar 9, 2023
- Messages
- 3
- Reaction score
- 0
Java:
class Solution {
public void moveZeroes(int[] nums) {
int left=0;
int right=0;
for(int i=0;i<nums.length;i++){
if(nums[i]==0){
left=i;
right=i+1;
break;
}
}
while(right<nums.length){
if(nums[right]!=0 && nums[left]==0){
int temp=nums[right];
nums[right]=nums[left];
nums[left]=temp;
left++;
right++;
}
else{
right++;
}
}
}
}