soulmachine / leetcode

LeetCode题解,151道题完整版。
BSD 3-Clause "New" or "Revised" License
11.27k stars 3.43k forks source link

there is a problem about "Two Sum" #18

Open Gdreamlend opened 10 years ago

Gdreamlend commented 10 years ago

In a case the code is not right: if gap == num[i] then you will get result[0]=result[1]

soulmachine commented 10 years ago

I couldn't understand your question, I just tested my code, and my code can pass the "Two Sum" on LeetCode.

Could you be more specific about your question?

Gdreamlend commented 10 years ago

my question is :if the test list is {3,2,4} and target is 6, your code would not be accepted

2014-04-16 17:46 GMT+08:00 Frank Dai notifications@github.com:

I couldn't understand your question, I just tested my code, and my code can pass the "Two Sum" on LeetCode.

Could you be more specific about your question?

— Reply to this email directly or view it on GitHubhttps://github.com/soulmachine/leetcode/issues/18#issuecomment-40581311 .

soulmachine commented 10 years ago

I tested this case, the output of my code is 2, 3, which is correct.

Gdreamlend commented 10 years ago

I will try it again latter ,thanks for your reply.

2014-04-17 15:59 GMT+08:00 Frank Dai notifications@github.com:

I tested this case, the output of my code is 2, 3, which is correct.

— Reply to this email directly or view it on GitHubhttps://github.com/soulmachine/leetcode/issues/18#issuecomment-40690242 .

lmscsomg commented 10 years ago

I met the same problem, I think maybe you can change the codeif(mapping.find(gap) !=mapping.end()) into if(mapping.find(gap)!=mapping.end() && i!=mapping[gap]):)