Can someone tell me how to take input and give output in leetcode problems.
Like for eg : - LeetCode
pastebin - This is my solution,but I don’t know to take input the way it is given in the question.Also,the output method is different.
Can someone tell me how to take input and give output in leetcode problems.
Like for eg : - LeetCode
pastebin - This is my solution,but I don’t know to take input the way it is given in the question.Also,the output method is different.
In leetcode, a function is given where the input is already taken. You just have to write the logic inside the function and return the required output
you already have your input in vector “nums” and integer “target”. Just implement your logic and you are good to go.
Done exactly what you said,still having problem in returning 2 values i &j.
Would be great help if someone just write the returning statement,else everything is fine i guess.
Edit : pastebin ,Finally submitted it using vector.
That’s nice; what else you could have done is : map each number with it’s index then for each element in vector search for the target-v[i]
element in the map. If found then return { mp[v[i]] , mp[target-v[i]]}
, and as it is mentioned that there will be always a solution exist.
I have seen similar problem in Daily Coding Problem and this is my solution for it [Problem statement is present in the code] .