27. Remove Element*

原创 2016年08月29日 20:44:20

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 in place with constant memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Example:
Given input array nums = [3,2,2,3], val = 3

Your function should return length = 2, with the first two elements of nums being 2.

My code:

class Solution(object):
    def removeElement(self, nums, val):
        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """
        n = len(nums)  
        count = 0  
        for i in range (n):  
            if nums[i]!= val:  
                nums[count] = nums[i]  
                count =count +1 
        return count

Same to the Move zeros problem, but sort of forgotten
版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode(27)Remove Element

题目Given an array and a value, remove all instances of that value in place and return the new length....
  • fly_yr
  • fly_yr
  • 2015年08月12日 16:50
  • 1590

27. Remove Element Leetcode Python

Given an array and a value, remove all instances of that value in place and return the new length. ...
  • hyperbolechi
  • hyperbolechi
  • 2015年01月29日 11:53
  • 827

LeetCode 27 — Remove Element(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-element/ Given an array and a value, remove all instance...
  • dragon_dream
  • dragon_dream
  • 2014年02月23日 15:54
  • 4107

Leetcode:27. Remove Element(JAVA)

【问题描述】 Given an array and a value, remove all instances of that value in place and return the n...
  • u010183658
  • u010183658
  • 2016年03月07日 22:15
  • 975

[leetcode] 27. Remove Element 解题报告

题目链接:https://leetcode.com/problems/remove-element/ Given an array and a value, remove all instance...
  • qq508618087
  • qq508618087
  • 2015年12月27日 11:25
  • 277

27. Remove Element -- Python

27. Remove ElementGiven an array and a value, remove all instances of that value in-place and return...
  • Chris_zhangrx
  • Chris_zhangrx
  • 2018年01月04日 23:39
  • 74

(Java)LeetCode-27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. ...
  • u012848330
  • u012848330
  • 2016年06月08日 15:16
  • 648

LeetCode 27:Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. ...
  • sunao2002002
  • sunao2002002
  • 2015年06月03日 23:05
  • 1988

[leetcode] 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. ...
  • TstsUgeg
  • TstsUgeg
  • 2016年03月22日 10:58
  • 168

LeetCode 27. Remove Element

分类: Array ; Two Points 问题描述: Given an array and a value, remove all instances of that value in...
  • u014006007
  • u014006007
  • 2016年11月30日 21:31
  • 234
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:27. Remove Element*
举报原因:
原因补充:

(最多只允许输入30个字)