Leetcode 26 - Remove Duplicates from Sorted Array - Golang

preview_player
Показать описание
Hi Gophers!
Here's the Golang solution for Leetcode 26, Remove Duplicates from Sorted Array. :)
Solve this as part of the top 150 leetcode interview questions or for easy beginner leetcode preparation.

Medium Remove Duplicates from Sorted Array II video here:

0:00 Question
0:36 Visualise the Solution
1:11 Key Solution Concept
3:27 Coding it out

Explore other playlists here for your coding interviews:
1. Top 150 leetcode questions:
2. Easy leetcode questions:
3. Top Common Array leetcode questions:

All the best for coding interviews! :)

#removeduplicates #leetcode #codinginterview
#golang #golangtutorial #gophers
Рекомендации по теме
Комментарии
Автор

When I tried the code in my local IDE, its giving me error on line 4 that "prevElement declared and not used" and on line 14 as "cannot use count (variable of type int) as []int value in return statement".
func duplicatesRemover(nums []int) int {
if len(nums) == 0 {
return 0
}

count := 1
for i := 1; i < len(nums); i++ {
if nums[i] != nums[i-1] {
nums[count] = nums[i]
count++
}
}
return count
}
Is this above solution correct?

ravikiranm-enjr
Автор

the way you explained is easy to understand, you just gained another subscriber

ainul