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 ?
Master Data Structures & Algorithms for FREE at AlgoMap.io/
I saw so many videos but your explanation was great for me to understand the concept. Thank you
can you please also make videos on daily challenges of leetcode
love your videos, you teach us in nice way👍👍
The drawing is so helpful! Can you do calculator leet code question?
thank you for the wonderful video Greg, very useful thanks again
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