先增后减 有进有退
https://leetcode-cn.com/problems/valid-anagram/
func isAnagram(s, t string) bool {
if len(s) != len(t) {
return false
}
cnt := map[rune]int{}
for _, ch := range s {
cnt[ch]++
}
for _, ch := range t {
cnt[ch]--
if cnt[ch] < 0 {
return false
}
}
return true
}
https://leetcode-cn.com/problems/valid-anagram/solution/you-xiao-de-zi-mu-yi-wei-ci-by-leetcode-solution/

浙公网安备 33010602011771号