mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
Merge pull request #160 from brenobaptista/suggestion-242
Suggestion 242
This commit is contained in:
@ -1,5 +1,26 @@
|
||||
package leetcode
|
||||
|
||||
// suggestion
|
||||
func isAnagram2(s string, t string) bool {
|
||||
hash := map[rune]int{}
|
||||
|
||||
for _, value := range s {
|
||||
hash[value]++
|
||||
}
|
||||
|
||||
for _, value := range t {
|
||||
hash[value]--
|
||||
}
|
||||
|
||||
for _, value := range hash {
|
||||
if value != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 解法一
|
||||
func isAnagram(s string, t string) bool {
|
||||
alphabet := make([]int, 26)
|
||||
|
@ -45,6 +45,21 @@ func Test_Problem242(t *testing.T) {
|
||||
para242{"rat", "car"},
|
||||
ans242{false},
|
||||
},
|
||||
|
||||
{
|
||||
para242{"a", "ab"},
|
||||
ans242{false},
|
||||
},
|
||||
|
||||
{
|
||||
para242{"ab", "a"},
|
||||
ans242{false},
|
||||
},
|
||||
|
||||
{
|
||||
para242{"aa", "bb"},
|
||||
ans242{false},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 242------------------------\n")
|
||||
|
Reference in New Issue
Block a user