leetcode 27: Remove Element
2015-07-03 12:05
267 查看
class Solution { public: int removeElement(vector<int>& nums, int val) { if(nums.empty()) return 0; if(nums.size()==1) { if(nums[0]==val) return 0; else return 1; } int res=0; int end=nums.size()-1; for(int i=0;i<nums.size()&&end>=i;i++) { if(nums[i]!=val) res++; else { swap(nums[i],nums[end]); end--; i--; } } return res; } };
相关文章推荐
- 普通用户不能第一时间升级Win10 Insider用户最先
- Navicat for mysql 远程连接 mySql数据库10061错误问题
- C# 泛型使用笔记
- leetcode 26: Remove Duplicates from Sorted Array
- Ext.bind()使用方法
- leetcode 25: Reverse Nodes in k-Group
- 简单的按钮拖动事件
- UC天气预报接口 测试
- 关于WebView的loaddata方法中文乱码问题解决,记录而已。
- C++ 字典排序 原理与实现
- Spring Java-based容器配置(二)
- leetcode 24: Swap Nodes in Pairs
- java设计模式思想
- tableView下拉图片放大
- Android Fragment 真正彻底的解决(下一个)
- 跨域请求数据解决方案整理
- Visual Studio中修改项目的输出目录
- leetcode 23: Merge k Sorted Lists
- 【RAC】 RAC For W2K8R2 安装--卸载(八)
- tomcat8项目引入servlet-api.jar包后报错