Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ritik-agrawal/680facd8262ebfa6fa8658402823cb34 to your computer and use it in GitHub Desktop.
Save ritik-agrawal/680facd8262ebfa6fa8658402823cb34 to your computer and use it in GitHub Desktop.
class Solution {
public int removeDuplicates(int[] ar) {
var nui = 1;
var cnt = 1;
var len = ar.length;
for(int cur = 1; cur < len; cur++){
if(ar[cur-1] == ar[cur]){
cnt++;
} else {
cnt = 1;
}
if (nui < cur){
ar[nui] = ar[cur];
}
if (cnt <= 2){
nui++;
}
}
return nui;
}
}
@ritik-agrawal
Copy link
Author

Leet Code

Remove duplicates from the given array with at most twice the repetition.

Achievement

The above question is solved by me. The solution provided is in place which means that the space complexity is O(n) and it beats 100% of the total submissions with a runtime of 0ms as computed by LeetCode.

Link of the submission: click here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment