LeetCode #27
来源:互联网 发布:linux延时函数usleep 编辑:程序博客网 时间:2024/05/13 02:24
题目描述:
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.
较简单,做法和LeetCode #26 - remove duplicates from sorted array一样。
class Solution {public: int removeElement(vector<int>& nums, int val) { int i=0; int j=0; while(j<nums.size()) { if(nums[j]!=val) { nums[i]=nums[j]; i++; j++; } else j++; } return i; }};
阅读全文
0 0
- leetcode-27
- LeetCode #27
- leetcode 27
- [Leetcode]Leetcode 27:Remove Element
- leetcode note--leetcode 27 Remove Element
- LeetCode(27)Remove Element
- [leetcode 27] Remove Element
- Leetcode【27】:Implement strStr
- LeetCode 27 Valid Palindrome
- [leetcode 27] Remove Element
- [Leetcode] 27 - Remove Element
- leetcode|27|Remove Element
- LeetCode | #27 Remove Element
- LeetCode 27 : Remove Element
- [leetcode]27 Reverse Bits
- LeetCode 27 Remove Element
- leetcode-27 Remove Element
- leetcode 27 Remove Element
- python启动应用程序和终止应用程序
- 秒杀系统架构分析与实战
- 用EasyX绘制多球碰撞中的碰撞代码
- Git的使用说明
- SQL server2008获取创建表里各列的属性
- LeetCode #27
- 1819: [JSOI]Word Query电子字典
- AIX系统NONCOMP内存占比过高导致换页内存使用过多问题
- SQLServer 镜像配置操作
- android集成微信分享
- JDK8日期处理API
- 针对引入SSZipArchive冲突的非常见解决
- pom文件说明
- top.location.href、parent.location.href