LeetCode Remove Duplicates from Sorted Array
来源:互联网 发布:nginx 限制ip访问 编辑:程序博客网 时间:2024/05/16 14:25
这道题的Array是已经排序好的。用i,j两个指针,其中i指针以前的数据全部都保持不重复,j指针用于遍历原数组,j指针遇到与前一个数(即i指针所指向的数据)不同时即将数据添加到i指针末尾,并移动i指针。
class Solution {public: int removeDuplicates(vector<int>& nums){ int i=0; int j=1; int n=nums.size(); if (n==0) { return 0; } while (j<n) { if (nums[i]==nums[j]) { j++; }else{ nums[++i]=nums[j]; } } return i+1; }};
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- Linux Shell 常用技巧
- 日经社説 20150627 企業は株主総会を市場との対話の起点に
- 判断是否移动客户端
- Jboss7类加载器
- 社説 20150627 自民若手勉強会 看過できない「報道規制」発言
- LeetCode Remove Duplicates from Sorted Array
- ListView中按钮监听器 设置 及 优化
- 社説 20150627 安保法案審議 戦略的な曖昧性は確保したい
- 计数排序
- Yii 分页器Pagesize的设置方法
- ListView与ListView里的Button焦点冲突
- 移动APP产品原型设计工具
- jquery修改/追加/删除html网页中的内容示例
- eclipse中设置自动调整代码格式的方式