Find the Duplicate Number

2018/1/18 posted in  leetcode

class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        unordered_map<int, int> map;
        int res = 0;
        for (int i = 0; i<nums.size(); i++) {
            if (map[nums[i]]==0) {
                map[nums[i]]++;
            }else{
                res = nums[i];
            }
        }
        return res;
    }
};