Accepted solution to two sum problem in leetcode