Skip to content

Latest commit

 

History

History
16 lines (15 loc) · 350 Bytes

1. Two Sum.md

File metadata and controls

16 lines (15 loc) · 350 Bytes
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> m;
        for (int i = 0; i < nums.size(); ++i) {
            if (m.count(target - nums[i])) {
                return {m[target - nums[i]], i};
            }
            m[nums[i]] = i;
        }
        return {};
    }
};