Advertisement
nikunjsoni

1

Jun 21st, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> twoSum(vector<int>& nums, int target) {
  4.         unordered_map<int, int> indices;
  5.         for (int i = 0; i < nums.size(); i++) {
  6.             if (indices.find(target - nums[i]) != indices.end()) {
  7.                 return {indices[target - nums[i]], i};
  8.             }
  9.             indices[nums[i]] = i;
  10.         }
  11.         return {};
  12.     }
  13. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement