leetcode Remove Element 1.3 难度系数1
2014-01-24 11:21
477 查看
Question:
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
public int removeElement(int[] A, int elem) { int index = 0; for (int i = 0; i < A.length ; i++) { if(A[i]!=elem){ A[index++]=A[i]; } } return index; }
相关文章推荐
- leetcode Balanced Binary Tree 1.10 难度系数1
- leetcode JAVA Unique Paths 2.14 难度系数2
- leetcode Integer to Roman 难度系数3 3.5
- leetcode JAVA Unique Paths II 难度系数3 3.21
- leetcode JAVA Validate Binary Search Tree 难度系数3 3.35
- leetcode JAVA Word Ladder 3.44 难度系数3
- 数组逆序(难度系数:半颗星)
- leetcode Minimum Depth of Binary Tree 1.11 难度系数1
- leetcode Valid Number 2.15 难度系数2
- leetcode 3Sum 难度系数 3.6
- leetcode JAVA Minimum Path Sum 难度系数3 3.22
- leetcode JAVA Binary Tree Level Order Traversal 难度系数3 3.36
- leetcode JAVA Palindrome Partitioning 3.45 难度系数3
- 回文字符串(难度系数:半颗星)
- 找规律输出正方形(难度系数:2)
- leetcode Path Sum 1.2 难度系数1
- leetcode Add Binary 2.16 难度系数2
- leetcode 3Sum Closest 难度系数3 3.7
- leetcode JAVA Simplify Path 难度系数3 3.23
- leetcode JAVA Construct Binary Tree from Preorder and Inorder Traversal 难度系数3 3.37