【LeetCode】 027. Remove Element
来源:互联网 发布:产品标贴制作软件 编辑:程序博客网 时间:2024/04/30 15:16
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.
public class Solution { public int removeElement(int[] nums, int val) { int i = 0, j = 0; while(i < nums.length){ if(nums[i] != val){ nums[j] = nums[i]; j++; } i++; } return j; }}
0 0
- LeetCode 027. Remove Element
- 【LeetCode】027.Remove Element
- 【LeetCode】 027. Remove Element
- [LeetCode] 027. Remove Element (Easy) (C++)
- LeetCode:Remove Element
- LeetCode: Remove Element
- [Leetcode] Remove Element
- LeetCode: Remove Element
- leetcode 39: Remove Element
- [LeetCode] Remove Element
- Leetcode: Remove Element
- Leetcode:Remove Element
- Leetcode:Remove Element
- Leetcode:Remove Element
- [LeetCode]Remove Element
- LeetCode-Remove Element
- LeetCode - Remove Element
- LeetCode | Remove Element
- Installing CUDA Toolkit 7.5 on Ubuntu 14.04 Linux
- tjut 1285
- ACM之Java输入输出
- 基于HTML5之APP微信支付集成实现
- org.eclipse.graphiti.ui.editor.DiagramEditorInput.<init>(Lorg/eclipse/emf/common/util/URI;Ljava/lang
- 【LeetCode】 027. Remove Element
- 快来看!Hadoop+Spark大数据分析最佳实践研修班(第5期)深圳开班啦!
- Mina入门教程(二)----Spring4 集成Mina
- CocosCreator自定义事件总结
- jsp分页显示的代码与详细步骤 复制代码
- 扫雷App的实现
- spoj 687 repeats
- android 6.0的权限问题
- Codeforces #280 Div.2 E.Vanya and Field 数学,数论