LeetCode Problem: Remove Duplicates from Sorted Array
Problem statement:
You are given an integer array nums sorted in increasing order, your task is to remove all the duplicates in place
Example:
Input:
nums = [1,1,2]
Expected output:
nums1 = [1,2,_]
If you would like to solve the problem on Leetcode, here is the link to the problem: https://leetcode.com/problems/remove-duplicates-from-sorted-array
Golang Solution:
func removeDuplicates(nums []int) int {
if len(nums) <= 1 {
return len(nums)
}
i, j := 0, 1
for i < len(nums)-1 && j < len(nums) {
if nums[i] == nums[j] {
j += 1
} else {
i += 1
nums[i] = nums[j]
}
}
return i+1
}