4 line O(nlogn) extremely easy Python solution

  • 1
    def removeElement(self, nums, val):
        if val in nums:
            nums.sort(key=lambda x:x==val)
            return nums.index(val)
        return len(nums)

    Sorting costs O(nlogn), but this is very easy-understand.

Log in to reply

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