#๐Ÿ”’ What do leetcode want me to return???

29 messages ยท Page 1 of 1 (latest)

wind torrent
woeful apexBOT
#

@wind torrent

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

limber oxide
wind torrent
#

yeah?

#

i also modified the list btw

#
nums = [min(nums) + i for i in range(counter)]
#

plus i checked in other interpreter alr

limber oxide
#

when the code's being ran and tested, leetcode is keeping hold of that nums list, and is checking its values after the function runs, because they're expecting you to change that list
but when you do nums = whatever, you aren't editing that original list, you're instead actually creating a brand new list

wind torrent
#

???????

#

oh okay

#

lemme try again ๐Ÿ™‚

#

i cant use list comprehension ๐Ÿ˜ฆ

limber oxide
#

so long as at no point you do nums =, then yeah, it counts ๐Ÿ˜„
(you can also do nums[i] =, or call any methods, but just never specifically nums =)

wind torrent
#

then why in the original code, it says my output is [1, 1]?

#

wow it got me wrong again. its example consists of consecutive numbers!

limber oxide
#

see what the question says for example 1, which is the same as that input

#

you got given an input list of [1, 1, 2], and leetcode expected for that list to be changed to start with [1, 2], basically

wind torrent
#

yeah so i see 1 and 2

#

i thought that only return consecutive outputs

#
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        new = list(set(nums))
        new.sort()
        counter = 1
        pointer = 0
        expected_number = min(nums)
        while expected_number in new:
            counter += 1
            pointer += 1
            expected_number = new[pointer]

        # Clears the list (setup)
        for i in range(len(nums)):
            nums.pop(0)

        # Add the values
        for i in range(counter):
            nums.append(new[i])

        return counter
#

i hope this works

#

oh nvm

#
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        new = list(set(nums))
        new.sort()

        # Clears the list (setup)
        for i in range(len(nums)):
            nums.pop(0)

        # Add the values
        for i in range(len(new)):
            nums.append(new[i])

        return len(new)
#

this works just like you said

#

thanks ๐Ÿ˜„

#

!close

woeful apexBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.