27. Remove Element Leetcode Python
2015-01-29 11:53
405 查看
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.
1.两个指针 count index
2.当 A[index]!=elem时候就A[count]=A[index]
we need two pointers count and index
when A[index]!=elem A[count]=A[index]
class Solution:
# @param A a list of integers
# @param elem an integer, value need to be removed
# @return an integer
def removeElement(self, A, elem):
count=0
index=0
while index<len(A):
if A[index]!=elem:
A[count]=A[index]
count+=1
index+=1
return count
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
1.两个指针 count index
2.当 A[index]!=elem时候就A[count]=A[index]
we need two pointers count and index
when A[index]!=elem A[count]=A[index]
class Solution:
# @param A a list of integers
# @param elem an integer, value need to be removed
# @return an integer
def removeElement(self, A, elem):
count=0
index=0
while index<len(A):
if A[index]!=elem:
A[count]=A[index]
count+=1
index+=1
return count
相关文章推荐
- leetcode 27. Remove Element python
- [C++]LeetCode 27: Remove Element(删除数组中指定元素)
- 【LEETCODE】27-Remove Element
- leetCode 27.Remove Element (删除元素) 解题思路和方法
- LeetCode-27. Remove Element(Java)
- LeetCode (27)Remove Element
- leetCode 27.Remove Element (删除元素) 解题思路和方法
- LeetCode 27. Remove Element(删除元素)
- Leetcode 27. Remove Element (Easy) (java)
- Leetcode 27. Remove Element (Easy) (cpp)
- LeetCode: 27. Remove Element
- leetcode Remove Element python
- leetcode Remove Element(27)
- 27. Remove Element LeetCode
- leetcode 27 Remove Element C++
- Python学习——leetcode(Remove Element)
- LeetCode 27:Remove Element
- Leetcode 27. Remove Element & 26. Remove Duplicates from Sorted Array
- [leetcode]27.Remove Element(Java)
- leetcode 27 Remove Element(移除数组中的与val相等的元素)