<LeetCode OJ> 27. Remove Element
来源:互联网 发布:restful 接口实例java 编辑:程序博客网 时间:2024/05/28 16:24
Total Accepted: 93055 Total Submissions: 285916 Difficulty: Easy
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
分析:
双指针遍历,cnt始终指向当前元素以前不为val的元素序列
class Solution {public: int removeElement(vector<int>& nums, int val) { int cnt=0; for (int i = 0; i<nums.size(); i++) if(nums[i] != val) nums[cnt++] = nums[i]; return cnt; }};
注:本博文为EbowTang原创,后续可能继续更新本文。如果转载,请务必复制本条信息!
原文地址:http://blog.csdn.net/ebowtang/article/details/50448834
原作者博客:http://blog.csdn.net/ebowtang
1 0
- <LeetCode OJ> 27. Remove Element
- [LeetCode OJ]27.Remove Element
- LeetCode OJ:Remove Element
- LeetCode OJ - Remove Element
- [LeetCode OJ]Remove Element
- LeetCode OJ Remove Element
- 【LeetCode OJ 027】Remove Element
- LeetCode OJ-27-Remove Element
- [LeetCode]27.Remove Element
- LeetCode --- 27. Remove Element
- LeetCode 27.Remove Element
- [Leetcode] 27. Remove Element
- [Leetcode] 27.Remove Element
- 【leetcode】27. Remove Element
- 【leetcode】27. Remove Element
- Leetcode 27. Remove Element
- LeetCode 27. Remove Element
- 27. Remove Element LeetCode
- TR4—TR6阶段测试项目管理
- RTAI 例子
- python中if __name__ == '__main__': 的解析
- Android Studio 配置 JDK1.8 使用Lambda表达式
- Oracle中dual虚拟表
- <LeetCode OJ> 27. Remove Element
- android studio中如何设置注释模板
- C语言指针-----指针与文件
- Oracle中的事务
- Codeforces 607A Chain Reaction 【二分 + dp】
- Ubuntu 15.10创建桌面快捷方式、启动器
- Intersection of Two Linked Lists 判断两个单链表里边有没有重叠,返回重叠的第一个节点
- 在CentOS 6.6 64bit上安装vim智能补全插件YouCompleteMe
- JDBC部分回顾注意点