26. Remove Duplicates from Sorted Array 發表於 2023-02-13 | 分類於 leetcode problemsolution123456789101112class Solution {public: int removeDuplicates(vector<int>& nums) { int slow = 0, fast = 0, n= nums.size(); while(fast<n){ // 維護nums[0...slow] 無重複就好 if(nums[slow] != nums[fast]) nums[++slow] = nums[fast]; fast++; } return slow+1; }}; analysis time complexity O(n) space complexity O(1)