Posts

26. Remove Duplicates from Sorted Array (Easy)

Image
Remove Duplicates from Sorted Array is an Easy level problem. Given an array of integers sorted in non-decreasing (aka, increasing) order, remove all the duplicate values IN PLACE and return the number of unique values in the list. My first solution to this was:  c lass Solution : def removeDuplicates ( self , nums : list[ int ]) -> int : dupeCount = 0 origLength = len (nums) i = 0 while (i < len (nums) - 1 ): thisElem = nums[i] nextElem = nums[i+ 1 ] while thisElem == nextElem: dupeCount += 1 if (i< len (nums)- 2 ): nums[i+ 1 :] = nums[i+ 2 :] else : nums[i+ 1 :] = [] if i+ 1 < len (nums): nextElem = nums[i+ 1 ] else : nextElem = None i += 1 return origLength - dupeCount That solution worked, but it was super slow...

Why are we here?

Hi there and thanks for visiting the FIRST POST in the blog. My name is Zack Jarrett and I'm a software developer working on Mac desktop automation, desktop financial software, games, and puzzles. The purpose of this blog is to collect my thoughts and reflections on development tasks. To begin with I'll be reflecting on LeetCode problems.