https://leetcode.com/problems/contains-duplicate/
package main
func main() {
nums := []int{1, 2, 3, 1}
// nums := []int{1, 2, 3, 4}
containsDuplicate(nums)
}
// 제출 코드
func containsDuplicate(nums []int) bool {
intMap := make(map[int]bool)
check := []int{}
for _, num := range nums {
if _, val := intMap[num]; !val {
intMap[num] = true
check = append(check, num)
} else {
intMap[num] = false
}
}
if len(nums) == len(check) {
return false
} else {
return true
}
}
'Algorithm > Go' 카테고리의 다른 글
[LeetCode] Minimum Index Sum of Two Lists (0) | 2022.01.03 |
---|---|
[LeetCode] Merge Two Sorted Lists (0) | 2021.12.26 |
[LeetCode] Rotate String (0) | 2021.12.20 |
[Leetcode] Single Number (0) | 2021.12.20 |
[Leetcode] Majority Element (0) | 2021.12.19 |