美文网首页
2022-01-30

2022-01-30

作者: 16孙一凡通工 | 来源:发表于2022-01-30 10:42 被阅读0次

    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;
          
          }
    

    相关文章

      网友评论

          本文标题:2022-01-30

          本文链接:https://www.haomeiwen.com/subject/qcyqkrtx.html