27. Remove Element
来源:互联网 发布:mac 双系统分区格式 编辑:程序博客网 时间:2024/06/14 03:27
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.
题目类似 26. Remove Duplicates from Sorted Array。如下:
class Solution { public int removeElement(int[] nums, int val) { int index = 0; for (int i = 0; i < nums.length; ++ i){ if (nums[i] != val){ nums[index++] = nums[i]; } } return index; }}
阅读全文
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
- ZOJ 2760 How Many Shortest Path
- 优先队列
- 【XSY1162】鬼计之夜 最短路
- C#中winform窗体的美化控件 iriskin(一)
- 以Point类为基础,定义一个平面中的Circle类:
- 27. Remove Element
- 程序设计的时间问题
- Hotal (巧妙地dp设计)
- SSD移植
- opencv3编程入门
- QT简单实验——计算器
- HDU 6154 CaoHaha's staff(【数学规律题】)
- this关键字杂谈
- eclipse相关快捷键