Back to course home
0% completed
Vote For New Content
Easy 4 line java code
Sachin Dev S
Sep 24, 2024
class Solution { public int moveElements(int[] arr) { int slow = 0, fast = 1, n = arr.length; while(fast < n && slow < n) { if(arr[slow] != arr[fast]) { slow++; arr[slow] = arr[fast]; } fast++; } return slow + 1; } }
1
0
Comments
Comments
On this page
Problem Statement
Try it yourself