leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0001.cpp (365B)


      1 class Solution {
      2   public:
      3     vector<int> twoSum(vector<int> &nums, int target) {
      4         unordered_map<int, int> um;
      5         for (int i = 0; i < nums.size(); i++)
      6             if (um.find(target - nums[i]) != um.end())
      7                 return {um[target - nums[i]], i};
      8             else
      9                 um.insert(make_pair(nums[i], i));
     10         return {};
     11     }
     12 };