Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 80. Remove Duplicates from Sorted Array II

Posted on 2021-04-06 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size();
if (n < 2) return n;
int slow = 2, fast = 2;
while (fast < n) {
if (nums[slow - 2] != nums[fast]) {
nums[slow] = nums[fast];
++slow;
}
++fast;
}
return slow;
}
};
# Array# Two Pointers
LeetCode 88. Merge Sorted Array
LeetCode 26. Remove Duplicates from Sorted Array
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%