Leetcode Go Check if N and Its Double Exist
Check If N and Its Double Exist - LeetCode
https://leetcode.com/problems/check-if-n-and-its-double-exist/
- Go 言語で取り組んだメモ
回答
[Go] Simple solution | O(N) - Check If N and Its Double Exist - LeetCode
https://leetcode.com/problems/check-if-n-and-its-double-exist/solutions/1308897/go-simple-solution-o-n/
func checkIfExist(arr []int) bool {
dict := map[int]bool{}
for _, v := range arr {
if dict[2*v] || (dict[v/2] && v%2 == 0) {
return true
}
dict[v] = true
}
return false
}