Skip to content

Commit

Permalink
26. Remove Duplicates from Sorted Array
Browse files Browse the repository at this point in the history
  • Loading branch information
SE-MahmoudAbdelaal committed May 31, 2024
1 parent fe24100 commit 196a8b2
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

class Solution {
public int removeDuplicates(int[] nums) {
LinkedHashSet<Integer> hashSet=new LinkedHashSet<>();
for (int i = 0; i < nums.length; i++) {
hashSet.add(nums[i]);
}
int index=0;
for (Integer hasset : hashSet) {
nums[index]=hasset;
index++;
int index=1;
for (int i = 1; i < nums.length; i++) {
if (nums[i]!=nums[i-1]) {
nums[index++]=nums[i];

}
return index;
}
return index;
}
}

0 comments on commit 196a8b2

Please sign in to comment.