Remove Element
来源:互联网 发布:在淘宝免费买东西app 编辑:程序博客网 时间:2024/06/05 01:54
Remove Element
Total Accepted: 7901 Total Submissions: 24070Given 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.
The tricky part is unless check discussion, you don't know what the question really means
public class Solution { public int removeElement(int[] A, int elem) { int len = A.length; if (A==null){ return 0; } int i = 0; int count = 0; while(i<len){ if(A[i] == elem){ i++; count++; } else{ A[i-count] = A[i]; i++; } } return A.length-count; }}
0 0
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- java运行Windows命令
- Set Matrix Zeroes
- coding style
- Merge Sorted Array
- Swap Nodes in Pairs
- Remove Element
- Valid Binary Search Tree
- Valid Palindrome
- Word Ladder
- 写在2/11
- iOS7 兼容适配
- 机器学习的最佳入门学习资源
- 《Win32多线程程序设计》(6)---事件(Event Objects)
- CSDN 2013年终总结