package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
26. Remove Duplicates from Sorted Array
Solution idea
Two Pointers
双指针的物理意义:
慢指针 (l
): 指向目前为止最后一个 dedup 过的元素
快指针 (r
): 不停的往前走
机制:
每当r
指向的元素值不同于l
指向的元素的值,把r
指向的元素值赋值给l+1
Time complexity = $O(n)$