funcisAnagram1(s, t string)bool { var c1, c2 [26]int for _, ch := range s { c1[ch-'a']++ } for _, ch := range t { c2[ch-'a']++ } return c1 == c2 }
funcisAnagram2(s, t string)bool { iflen(s) != len(t) { returnfalse } cnt := map[rune]int{} for _, ch := range s { cnt[ch]++ } for _, ch := range t { cnt[ch]-- if cnt[ch] < 0 { returnfalse } } returntrue }
functwoSum(nums []int, target int) []int { m := make(map[int]int) for index, val := range nums { if preIndex, ok := m[target-val]; ok { return []int{preIndex, index} } else { m[val] = index } } return []int{} }