https://leetcode.com/problems/remove-duplicates-from-sorted-array/
in-place? 제자리에서 풀라는 건가?
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
memory = {}
for num in nums:
if memory.get(num):
continue
memory[num] = True
sorted_nums = sorted(memory.keys())
count = len(sorted_nums)
for (index, num) in enumerate(nums):
if index < count:
nums[index] = sorted_nums[index]
continue
nums[index] = count
return count
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) < 1:
return 0
change_index = 1
for i in range(0, len(nums)):
# print(nums[i])
if i != 0 and nums[i-1] != nums[i]:
nums[change_index] = nums[i]
change_index += 1
return change_index