Remove Duplicates from Sorted Array
Problem Problem_Link My Answer 1 hour limit no search on internet My code class Solution { public int removeDuplicates(int[] nums) { if(nums==null ||nums.length==0) return 0; int temp = -101; int count=0; int pos=0; for(int i=0;i<nums.length;++i){ if(temp!=nums[i]){ temp=nums[i]; nums[pos]=nums[i]; ++count; ++pos; } } return count; } } Time complexity : $O(n)$ Space complexity : $O(1)$ My result Runtime: 2 ms, faster than 22.76% of Java online submissions for Remove Duplicates from Sorted Array.