leetcode #26 in cpp
来源:互联网 发布:软件开发流程图软件 编辑:程序博客网 时间:2024/04/30 22:24
The question is to remove the duplicate within a sorted array and return the number of unique elements in the array.
Solution: keep a count of the unique numbers we have seen. The ith unique element should be saved in the (i-1)th entry in the array.
Code:
class Solution {public: int removeDuplicates(vector<int>& nums) { if(nums.empty()) return 0; int count = 1; for(int i = 1; i < nums.size(); i ++){ if(nums[i-1] != nums[i]) {//determine if nums[i] is duplicate nums[count] = nums[i]; count++; } } return count; }};
0 0
- leetcode #26 in cpp
- leetcode #12 in cpp
- Leetcode #13 in cpp
- Leetcode #14 in cpp
- leetcode %15 in cpp
- leetcode #16 in cpp
- leetcode #17 in cpp
- leetcode #18 in cpp
- leetcode #20 in cpp
- leetcode #21 in cpp
- leetcode #22 in cpp
- leetcode #23 in cpp
- leetcode #24 in cpp
- leetcode #25 in cpp
- leetcode #27 in cpp
- leetcode #28 in cpp
- leetcode #29 in cpp
- leetcode #30 in cpp
- arm平台tslib的编译与qte源代码包配置中的-qt-mouse-tslib--转载
- Spring中@Async用法
- 微信投票活动为何能帮助公众号粉丝增长?
- 裸辞太久,这些条件你还不将就?!
- SICP ex2-45
- leetcode #26 in cpp
- (礼拜三log)递归树算法2
- AppStore审核神速,大大提高了审核速度。
- 解决 Tomcat v7.0 Server at localhost was unable to start within 45 seconds
- [Ubuntu]Ubuntu下用雷鸟 Thunderbird 导入 Outlook 导出的 .pst 文件
- 写了一段时间博客后的反思... ...
- Activity的生命周期及启动模式整理
- LeetCode 128. Longest Consecutive Sequence(最长连续序列)
- Libevent源码分析-----日志和错误处理