Leetcode217 Contains Duplicate
題目 Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. 題意: 判斷陣列中是否有重複的值 解法 解法: 透過map資料結構,找出在陣列中是否有重複的值 func containsDuplicate(nums []int) bool { m := map[int]bool{} for _, v := range nums { if _, exist := m[v]; exist { return true } m[v] = true } return false } 加些測試,看看結果是不是如預期 import ( "github.com/stretchr/testify/assert" "testing" ) func Test_containsDuplicate(t *testing....