Update 0242.有效的字母异位词.md

添加0242.有效的字母异位词 go版本
This commit is contained in:
X-shuffle
2021-05-12 15:48:38 +08:00
committed by GitHub
parent 08781d4ceb
commit ad221247d6

View File

@ -92,16 +92,26 @@ Python
Go Go
```go ```go
func removeElement(nums []int, val int) int { func isAnagram(s string, t string) bool {
length:=len(nums) if len(s)!=len(t){
res:=0 return false
for i:=0;i<length;i++{ }
if nums[i]!=val { exists := make(map[byte]int)
nums[res]=nums[i] for i:=0;i<len(s);i++{
res++ if v,ok:=exists[s[i]];v>=0&&ok{
exists[s[i]]=v+1
}else{
exists[s[i]]=1
} }
} }
return res for i:=0;i<len(t);i++{
if v,ok:=exists[t[i]];v>=1&&ok{
exists[t[i]]=v-1
}else{
return false
}
}
return true
} }
``` ```