【Leetcode】【Easy】Remove Element
2014-12-04 22:28
281 查看
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.
解题思路:
新建一个newAarryNum,作为新生成数组的下标;
新生数组重新码入除elem以外的元素;
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
解题思路:
新建一个newAarryNum,作为新生成数组的下标;
新生数组重新码入除elem以外的元素;
class Solution { public: int removeElement(int A[], int n, int elem) { int newArrayNum = 0; for (int i=0; i<n; ++i) { if (A[i] != elem) { A[newArrayNum++] = A[i]; } } return newArrayNum; } };
相关文章推荐
- LeetCode刷题(C++)——Remove Element(Easy)
- 【leetcode】Remove Element (easy)
- LeetCode-27-Remove Element(数组)-Easy
- [Leetcode 27, easy] Remove Element
- leetcode_27_ Remove Element (easy)
- 【Leetcode-easy】Remove Element
- LeetCode-Easy刷题(8) Remove Element
- leetcode 027 Remove Element(难易度:Easy)
- [Leetcode 67, easy] Add Binary
- leetcode 7 easy的难度但是还是再次的提醒了我 math的重要性
- 【leetcode】【Easy】【258. Add Digits】【Math】
- Leetcode 27. Remove Element (Easy) (cpp)
- [leetcode 27]Remove Element
- Leetcode 121. Best Time to Buy and Sell Stock (Easy) (cpp)
- LeetCode-27. Remove Element
- [Leetcode 172, Easy] Factorial Trailing Zeroes
- LeetCode-8-String to Integer (atoi) (String/Num)-Easy
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
- LeetCode题解——Remove Element
- Leetcode 175. Combine Two Tables(Easy)