[leetcode]80. Remove Duplicates from Sorted Array II
2016-09-02 00:15
113 查看
//已排序,则做in-place置换 class Solution { public: int removeDuplicates(vector<int>& nums) { int n=nums.size(); if(n<3) return n; int i=2; for(int j=2;j<n;j++) { if(nums[j]!=nums[i-2]) { nums[i++]=nums[j]; } } return i; } };
相关文章推荐
- leetcode -- Populating Next Right Pointers in Each Node
- leetcode JAVA Jump Game 难度系数3 3.18
- 【LeetCode】Palindrome Number
- [LeetCode 题解]: Merge k Sorted Lists
- [LeetCode] Partition List
- leetcode: Best Time to Buy and Sell Stock III
- 【leetcode】Reverse Nodes in k-Group (hard)☆
- LeetCode | Add Two Numbers
- [leetcode] 81.Search in Rotated Sorted Array II
- LeetCode_112 Path Sum
- Leetcode: Gray Code
- leetcode-50 Pow(x, n) 剑指Offer题11 数值的整数次方
- LeetCode 066 Plus One
- 【leetcode】Array—— Minimum Path Sum(64)
- LeetCode(62)-Two Sum
- 【一天一道LeetCode】#74. Search a 2D Matrix
- [LEETCODE] 372. super pow
- leetcode_378 Kth Smallest Element in a Sorted Matrix
- LeetCode No.231 Power of Two
- Leetcode——216. Combination Sum III