题解 | #出现一次的牛#

出现一次的牛

https://www.nowcoder.com/practice/ed54a59697a244d2a3c656191d575f22

using System;
using System.Collections.Generic;

class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型
     */
    public int findSingleCow (List<int> nums) {
        // write code here
        Dictionary<int,int> res = new Dictionary<int,int>();
        foreach(int num in nums)
        {
            if(res.ContainsKey(num))
            {
                if(res[num]==1)
                {
                    res[num]++;
                }
                else
                {
                    res.Remove(num);
                }
            }
            else
            {
                res.Add(num, 1);
            }
        }
        ICollection<int> keys = res.Keys;
        foreach (int key in keys)
        {
            return key;
        }
        return -1;
    }
}

全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务