The next problem in our Leetcode series will be the Contains Duplicate Problems which is as follows: "Given an integer array nums, return true if any value appears more than once in the array, otherwise return false."
The solutions to the problem is pretty straight forward. We will be passing over the array once and storing each value we see in a hash map. If the Value is already in the hashmap we should return true.
func ContainsDuplicate(nums []int) bool {
hashMap := make(map[int]int)
for i := range nums {
_, prs := hashMap[nums[i]]
if prs == true {
return true
} else {
hashMap[nums[i]] = i
}
}
return false
}