AcWing 799. 最长连续不重复子序列 Go
原题链接
简单
作者:
LaChimere
,
2021-03-18 16:51:02
,
所有人可见
,
阅读 335
package main
import "fmt"
func max(x, y int) int {
if x < y {
return y
}
return x
}
func main() {
var n int
fmt.Scanf("%d", &n)
nums, exists := make([]int, n), make(map[int]int)
for i := 0; i < n; i++ {
fmt.Scanf("%d", &nums[i])
}
exists[nums[0]] = 0
anchor, res := 0, 1
for cur := anchor; cur < len(nums); cur++ {
if idx, ok := exists[nums[cur]]; ok {
for anchor <= idx {
delete(exists, nums[anchor])
anchor++
}
}
exists[nums[cur]] = cur
res = max(res, cur-anchor+1)
}
fmt.Println(res)
}
兄弟你没有填邀请码可以填一个,都可以得AC币!嘿嘿,谢谢兄弟
我的邀请码是:GUDFH