Skip to content

Commit

Permalink
Solve: Remove Duplicates from Sorted Array
Browse files Browse the repository at this point in the history
  • Loading branch information
fkdl0048 committed Oct 4, 2024
1 parent 3433adc commit 4bc1442
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions LeetCode/Remove Duplicates from Sorted Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.empty()) return 0;

int j = 1;
for (int i = 1; i < nums.size(); i++){
if (nums[i] != nums[i - 1]){
nums[j] = nums[i];
j++;
}
}

return j;
}
};

0 comments on commit 4bc1442

Please sign in to comment.