class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ a = [] for num in nums: if num not in a: a.append(num) return len(a) nums = [1,1,2] solve = Solution() print(solve.removeDuplicates(nums)) this is my method when running in online complier no error showing but when runs in leetcode showing error. Sir can explain me why this can happend ?
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ a = [] for num in nums: if num not in a: a.append(num) return len(a) nums = [1,1,2] solve = Solution() print(solve.removeDuplicates(nums)) this is my method showing error but online complier didn't show any error the reason why ?
This is one of the worst problem descriptions they have on LettCode. How could someone formulate such a simple task in such a complicated and unclear way? :)
Master Data Structures & Algorithms for FREE at AlgoMap.io/
When I can't understand something on Neetcode, I come here. Now, Greg Hogg is my first priority.
I saw so many videos but your explanation was great for me to understand the concept. Thank you
thank you for the wonderful video Greg, very useful thanks again
can you please also make videos on daily challenges of leetcode
love your videos, you teach us in nice way👍👍
If the array size is 1 it would throw an index error right
The drawing is so helpful! Can you do calculator leet code question?
why the error 'return' outside function?
Please make videos on leetcode POTD sir
Hi Greg could you please provide the provide the discord server link?
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a = []
for num in nums:
if num not in a:
a.append(num)
return len(a)
nums = [1,1,2]
solve = Solution()
print(solve.removeDuplicates(nums))
this is my method when running in online complier no error showing but when runs in leetcode showing error. Sir can explain me why this can happend ?
hi, you need to modify exactly the nums array that you have in your function, you should not create any new arrays
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a = []
for num in nums:
if num not in a:
a.append(num)
return len(a)
nums = [1,1,2]
solve = Solution()
print(solve.removeDuplicates(nums))
this is my method showing error but online complier didn't show any error the reason why ?
because you need do it in-place, that means you cannot use any extra space
@@amlet00 Thank you sir
This ain't easy mannnnn
return len(set(nums))
i think this gonna work , no ?
Yeah you should read the question again haha
Wont work because sets are unordered and the question asks to keep the order of the given array! So you cannot use a set data structure
This is one of the worst problem descriptions they have on LettCode. How could someone formulate such a simple task in such a complicated and unclear way? :)