Leetcode 27. Remove Element
来源:互联网 发布:网站站内优化 编辑:程序博客网 时间:2024/06/05 10:07
题目
Given an array and a value, remove all instances of that value in place and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
Example:
Given input array nums = [3,2,2,3], val = 3.Your function should return length = 2, with the first two elements of nums being 2.
解答
class Solution {public: int removeElement(vector<int>& nums, int val) { int end=nums.size(); for(int i=0;i<end;){ if(nums[i]==val){ swap(nums[i],nums[end-1]); end--; }else{ i++; } } return end; }};
0 0
- [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
- 【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
- 商品展示
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- Apache Spark 内存管理详解
- 【腾讯Bugly干货分享】Android减包 - 减少APK大小
- MIME协议个人笔记--第一篇
- Leetcode 27. Remove Element
- C++概述
- 统计一篇文本中空格、单词、句子、非字母字符个数
- Java语言概述
- 深度链接 Deep Link 开发遇到的坑
- 浏览器兼容问题项目总结(七)IE下未初始化为空,chrome下未初始化生产大量空格
- 重写父类方法、super关键字、调用父类构造器——Java
- 自定义apache日志格式
- qt5 中文乱码