Answered step by step
Verified Expert Solution
Link Copied!

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

image

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Foundations of Financial Management

Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta

10th Canadian edition

1259261018, 1259261015, 978-1259024979

More Books

Students also viewed these Programming questions

Question

Solve Problem 12.84 using the values of enthalpy from Table C.7.

Answered: 1 week ago

Question

3. What makes the blind spot of the retina blindpg105

Answered: 1 week ago