This commit is contained in:
陈兔子
2026-04-15 00:47:11 +08:00
parent 7f6e21ac59
commit f21cc94b00
+3 -3
View File
@@ -7,9 +7,9 @@ func HasDuplicate[T comparable](slice []T) bool {
seen := make(map[T]struct{}, len(slice))
for _, v := range slice {
if _, exists := seen[v]; exists {
return true // 发现重复
}
// 发现重复
if _, exists := seen[v]; exists { return true }
// 记录已见过的元素
seen[v] = struct{}{}
}