-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.go
28 lines (24 loc) · 770 Bytes
/
array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package top_interview_questions_easy
// containsDuplicate Problem: Contains Duplicate.
//
// LeetCode: https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/578/
func containsDuplicate(nums []int) bool {
exists := make(map[int]struct{})
if len(nums) == 0 {
return false
}
if len(nums) == 1 {
return false
}
for _, v := range nums {
if _, ok := exists[v]; ok {
return true
}
exists[v] = struct{}{}
}
return false
}
// Problem: Remove Duplicates from Sorted Array.
//
// LeetCode: https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/727/
// See: https://github.com/idexter/algorithms-and-datastructures/tree/master/leetcode/explore/learn/card/fun-with-arrays/deleting_items_from_an_array.go