Untitled
unknown
plain_text
10 months ago
861 B
7
Indexable
import unittest
def removeDuplicates(nums):
"""
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place
such that each unique element appears only once. The relative order of the elements should
be kept the same.
Modify the array in-place and return the number of unique elements.
"""
return 0 # TODO: Implement this function
class TestRemoveDuplicates(unittest.TestCase):
def test_case_1(self):
nums = [1, 1, 2]
expected_nums = [1, 2]
k = removeDuplicates(nums)
self.assertEqual(nums[:k], expected_nums)
def test_case_2(self):
nums = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4]
expected_nums = [0, 1, 2, 3, 4]
k = removeDuplicates(nums)
self.assertEqual(nums[:k], expected_nums)
if __name__ == "__main__":
unittest.main()Editor is loading...
Leave a Comment