27. Remove Element
来源:互联网 发布:linux 命令大全文库 编辑:程序博客网 时间:2024/06/10 04:08
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.
Show HintSubscribe to see which companies asked this question
快慢指针
public class Solution { public int removeElement(int[] nums, int val) { int p1 = 0 ; int p2 = 0 ; int len = nums.length; for(int i = 0;i<len;i++){ if(nums[i]!=val){ p1++; nums[p1-1]=nums[i]; } }return p1; }}
0 0
- [LeetCode]27.Remove Element
- LeetCode --- 27. Remove Element
- LeetCode 27.Remove Element
- [Leetcode] 27. Remove Element
- 27.Remove Element
- [Leetcode] 27.Remove Element
- 27. Remove Element
- 27. Remove Element
- 【leetcode】27. Remove Element
- 【leetcode】27. Remove Element
- 27. Remove Element
- 27. Remove Element
- 27. Remove Element
- Leetcode 27. Remove Element
- 27. Remove Element
- LeetCode 27. Remove Element
- 27. Remove Element LeetCode
- 27. Remove Element
- 3192: [JLOI2013]删除物品
- C++模拟C#事件委托机制(一)
- Linux 小知识点:创建变量
- 【bzoj 3192】: [JLOI2013]删除物品 树状数组+想法题
- 算日期模板
- 27. Remove Element
- Apache Kafka编程入门指南:设置分区数和复制因子
- EditText设置不自动弹出键盘
- 66. Plus One
- 云计算概念总结
- Problem B: 求各位数字之和
- 26. Remove Duplicates from Sorted Array
- 《看见》
- C++子类显示调用父类的构造函数