和大神们学习每天一题(leetcode)-Remove Element
2014-12-07 17:45
387 查看
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.
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 nFinalLen = 0; for (int nTemp = 0; nTemp < n; nTemp++) { if (A[nTemp] != elem) { A[nFinalLen] = A[nTemp]; nFinalLen++; } } return nFinalLen; } };
相关文章推荐
- 和大神们学习每天一题(leetcode)-Add Binary
- 和大神们学习每天一题(leetcode)-Reverse Integer
- 和大神们学习每天一题(leetcode)-Balanced Binary Tree
- 和大神们学习每天一题(leetcode)-Implement strStr()
- 和大神们学习每天一题(leetcode)-Remove Duplicates from Sorted List
- 和大神们学习每天一题(leetcode)-Symmetric Tree
- 和大神们学习每天一题(leetcode)-Length of Last Word
- 和大神们学习每天一题(leetcode)-Maximum Depth of Binary Tree
- 和大神们学习每天一题(leetcode)-Path Sum
- 和大神们学习每天一题(leetcode)-Plus One
- 和大神们学习每天一题(leetcode)-Sort Colors
- 和大神们学习每天一题(leetcode)-Intersection of Two Linked Lists
- 和大神们学习每天一题(leetcode)-ZigZag Conversion
- 和大神们学习每天一题(leetcode)-Minimum Depth of Binary Tree
- 和大神们学习每天一题(leetcode)-Pascal's Triangle
- 和大神们学习每天一题(leetcode)-Count and Say
- 和大神们学习每天一题(leetcode)-Binary Tree Level Order Traversal II
- 和大神们学习每天一题(leetcode)-Longest Common Prefix
- 和大神们学习每天一题(leetcode)-Merge Sorted Array
- 和大神们学习每天一题(leetcode)-Merge Two Sorted Lists