LeetCode Remove Element
2014-03-22 11:33
253 查看
题目:
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.
class Solution { public: //找到元素后,从数组结尾抽取数值覆盖 int removeElement(int A[], int n, int elem) { int k = 0; for(int i = 0; i < n-k; i++) { if(A[i] == elem) { if(i == n-1-k) { k++; break; } A[i] = A[n-1-k]; k++; i--; } } return n-k; } };
相关文章推荐
- [LeetCode] 3 remove element problems
- leetcode之Remove Element
- LeetCode Remove Element
- LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**
- leetcode remove-element
- LeetCode Remove Element
- leetcode 27. Remove Element python
- Remove Element [LEETCODE]
- LeetCode之Remove Element
- leetcode Remove Element
- leetcode removeElement
- LeetCode Remove Element
- 【LEETCODE】27-Remove Element
- LeetCode Remove Element
- leetcode 之Remove Element
- LeetCode Remove Element
- LeetCode 27. Remove Element(删除元素)
- LeetCode Remove Element
- LeetCode之Remove Element
- LeetCode(27)Remove Element