class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ front = len(nums)-1 behind = len(nums)-1 number = 0 while front >= 0: print 'now:', front, behind if nums[front] == val: print front, behind number += 1 nums[front], nums[behind] = nums[behind], nums[front] behind -= 1 front -= 1 print number return len(nums) - number
判断与指定目标不同
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """
size = 0 length = len(nums) for i in range(length): if nums[i] != val: