Tushar Koundal’s Post

day 7: (first week completed) LeetCode 26. Remove Duplicates from Sorted Array Key note -> since array is sorted , we know the duplicates will exist adjacent (neighbours) i = scan head , uniquePtr = write head So we only check neighbours nums[i] != nums[i-1] ---> unique element found write it down in array using uniquePtr (write head) increment it use i for scanning , uniquePtr for writehead (writing) why no set? set compromises space to o(n)since we are given a sorted array we get that adjacency for free , no need of set why both write head and scanner head starts at 1 and not at 0? simply the array is sorted , so whatsoever element is at nums[0] position their is no element beyond it to violate the no duplicacy rule , so we do not touch 0th position of array since its already unique. #day7of150daysofcode #week1of22weeksofcode #150daysofcode #Java #leetcode #dailycode

  • text

To view or add a comment, sign in

Explore content categories