Created
June 7, 2026 06:47
-
-
Save thinkphp/77fe6e3b794134a46d3d04da474b45e7 to your computer and use it in GitHub Desktop.
solutia optima pentru 2Sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<int> twoSum(vector<int> &nums, int target) { | |
| map<int,int> mp; | |
| int n = num.size(); | |
| for(int i = 0; i < n; ++i) { | |
| int a = nums[i]; | |
| int b = target - a; //calculezi complementarul. | |
| if( mp.find(b) != mp.end() ) { | |
| return { mp[ b ], i }; | |
| } | |
| mp[ a ] = i; | |
| } | |
| return {-1,-1}; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment