[LeetCode]Remove Element@python
2018-01-21 15:38
351 查看
Given an array and a value, remove all instances of that value
in-place and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input arrayin-place with O(1) extra memory.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Example:
in-place and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input arrayin-place with O(1) extra memory.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Example:
Given nums = [3,2,2,3], val = 3, Your function should return length = 2, with the first two elements of nums being 2.
class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ if not nums: return 0 j = 0 for i in range(len(nums)): if val != nums[i]: nums[j] = nums[i] j += 1 return j
相关文章推荐
- Python学习——leetcode(Remove Element)
- leetcode Remove Element python
- leetcode 27. Remove Element python
- LeetCode专题-Python实现之第27题:Remove Element
- [leetcode]Remove Element @ Python
- 27. Remove Element Leetcode Python
- LeetCode Remove Element
- leetcode_27. Remove Element ? 待解决
- [leetcode]Remove Nth Node From End of List @ Python
- leetCode 27.Remove Element (删除元素) 解题思路和方法
- LeetCode(27) Remove Element
- LeetCode之RemoveElement
- [Leetcode,python] Majority Element 众数
- 【LeetCode】27. Remove Element(移除元素)
- 【LeetCode with Python】 Remove Duplicates from Sorted Array II
- 【LeetCode with Python】 Remove Duplicates from Sorted Array
- LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**
- leetcode Remove Element
- LeetCode: Merge Two Sorted Lists, Remove Duplicates/Element, strStr()
- LeetCode Remove Element