Easy 8 Remove Element(27)
来源:互联网 发布:黑帽seo劫持跳转代码 编辑:程序博客网 时间:2024/05/22 00:55
Description
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.
Solution
思路和上题类似。
class Solution {public: int removeElement(vector<int>& nums, int val) { int count=0; for(size_t i=0;i<nums.size();i++){ if(nums[i]!=val) nums[count++]=nums[i]; } return count; }};
0 0
- Easy 8 Remove Element(27)
- Remove Element(easy)
- [Leetcode 27, easy] Remove Element
- Easy 27题 Remove Element
- LeetCode-27-Remove Element(数组)-Easy
- Leetcode OJ 27 Remove Element [Easy]
- LeetCode-Easy刷题(8) Remove Element
- 27. Remove Element [easy]
- 27. Remove Element (Easy)
- <LeetCode><Easy> 28 Remove Element
- 27. Remove Element [easy] (Python)
- leetcode 27. Remove Element (EASY)
- 27. Remove Element 难度:easy
- LeetCode刷题(C++)——Remove Element(Easy)
- leetcode 027 Remove Element(难易度:Easy)
- LeetCode(27)Remove Element
- LeetCode (27)Remove Element
- [LeetCode] 027. Remove Element (Easy) (C++)
- The first girlfriend -- AngularJS
- 表单form中对回车键的感应
- Android应用设置多个启动图标,动态列换应用图标
- 二级域名绑定二级目录的两种方法
- Vue学习笔记_02
- Easy 8 Remove Element(27)
- C++几个常用的关键字
- js、jquery操作父子iframe
- Python networks画网络图(转)
- [HDU4085]Peach Blossom Spring(斯坦纳树+dfs)
- poj 1125 Stockbroker Grapevine
- N皇后问题
- 内存管理
- jsp学习记录