Please help me with my code in python, my answer is right, but didn't pass test


  • 0
    N

    class Solution(object):
    def removeElement(self, nums, val):
    """
    :type nums: List[int]
    :type val: int
    :rtype: int
    """

        i=0
        for j in range (1, len(nums)):
            if nums[i] != val:
                i = i + 1
            elif nums[i] == val and nums[j] != val:
                
                nums[i], nums[j] = nums[j], nums[i]
                i = i + 1
        return i

Log in to reply
 

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