Not Accepted but Works on my computer


  • 0
    W
    class Solution:
    # @param {integer[]} nums
    # @param {integer} val
    # @return {integer}
    def removeElement(self, nums, val):
        z = [y for y in nums if y != val]
        return len(z)
    

    It works in my computer but is not accepted by OJ.


  • 0
    U

    You get the right length,but the real nums doesn't change.
    you can do like this:

    def removeElement(self, nums, val):

        z = [y for y in nums if y != val]
        for k,v in enumerate(z):
            nums[k] = v
        return len(z)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.