610.Two Sum - Difference equals to targe
1.Description(Medium)
Given an array of integers, find two numbers that theirdifference
equals to a target value.
where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are NOT zero-based.
Notice
It's guaranteed there is only one available solution
Example
Given nums =[2, 7, 15, 24]
, target =5
return[1, 2]
(7 - 2 = 5)
2.Code
当一个题目需要排序,但是要记录原有的index的时候需要用class Pair来同时保存下index和value.
这个题目就是需要。所以这个题目用hashmap没法做。
定住head,去遍历tail,直到找到答案。
Last updated
Was this helpful?