26. Remove Duplicates from Sorted Array ¶ Time: $O(n)$ Space: $O(n)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int removeDuplicates(vector<int>& nums) { int i = 0; for (const int num : nums) if (i < 1 || num > nums[i - 1]) nums[i++] = num; return i; } }; 1 2 3 4 5 6 7 8 9 10 11class Solution { public int removeDuplicates(int[] nums) { int i = 0; for (final int num : nums) if (i < 1 || num > nums[i - 1]) nums[i++] = num; return i; } } 1 2 3 4 5 6 7 8 9 10class Solution: def removeDuplicates(self, nums: list[int]) -> int: i = 0 for num in nums: if i < 1 or num > nums[i - 1]: nums[i] = num i += 1 return i