Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++I've solved the two sum problem from leetcode using 2 pointers as well as brute forcing it and now I'm trying to solve it using
c++I've solved the two sum problem from leetcode using 2 pointers as well as brute forcing it and now I'm trying to solve it using a hash table however I'm having trouble returning the index instead of the values. I was thinking of pairing the valued with an index but unsure. please help
1+ #include class Solution ( public: 2- 3 2456789 p 10+ 11 12 13 14- 15 16 17 18 19 20 vector twoSum (vector & nums, int target) { unordered_set hashTable; for (int i = 0; i < nums.size(); i++){ //for(int values nums) { int values = nums[i]; int potentialMatch target values; if(hashTable. find (potentialMatch) != hashTable.end()) # return vector (potentialMatch, values); estcase Run Code Result Debugger Your input Output else{ } return {}; Wrong Answer Runtime: 0 ms Expected hashTable.insert(values); [2,7,11,15] 9 [2,7] [0,1]
Step by Step Solution
★★★★★
3.40 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started