hashmap确定出现几次
Go版本
import (
"strings"
)
func uncommonFromSentences(s1 string, s2 string) []string {
s:=s1+" "+s2;
hashmap:=make(map[string]int);
arr:=strings.Split(s," ");
for i:=0;i<len(arr);i++{
hashmap[arr[i]]++;
}
res:=[]string{};
for key:=range hashmap{
if hashmap[key]==1{
res=append(res,key);
}
}
return res;
}
网友评论