mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #30 from X-shuffle/master
添加0242.有效的字母异位词 go版本 ; 添加0027.移除元素 go版本
This commit is contained in:
@ -129,7 +129,19 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```go
|
||||||
|
func removeElement(nums []int, val int) int {
|
||||||
|
length:=len(nums)
|
||||||
|
res:=0
|
||||||
|
for i:=0;i<length;i++{
|
||||||
|
if nums[i]!=val {
|
||||||
|
nums[res]=nums[i]
|
||||||
|
res++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
JavaScript:
|
JavaScript:
|
||||||
```
|
```
|
||||||
|
@ -91,8 +91,29 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```go
|
||||||
|
func isAnagram(s string, t string) bool {
|
||||||
|
if len(s)!=len(t){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
exists := make(map[byte]int)
|
||||||
|
for i:=0;i<len(s);i++{
|
||||||
|
if v,ok:=exists[s[i]];v>=0&&ok{
|
||||||
|
exists[s[i]]=v+1
|
||||||
|
}else{
|
||||||
|
exists[s[i]]=1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user