Created
October 4, 2015 16:41
-
-
Save viveksyngh/cdc05d1cc18151d48e4f to your computer and use it in GitHub Desktop.
Given an array of integers, find two numbers such that they add up to a specific target number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'Vivek' | |
| #Given an array of integers, find two numbers such that they add up to a specific target number. | |
| class Solution: | |
| # @param A : tuple of integers | |
| # @param B : integer | |
| # @return a list of integers | |
| def twoSum(self, A, B): | |
| Map = {} | |
| for i in range(len(A)) : | |
| if A[i] in Map : | |
| return [Map[A[i]] + 1, i + 1] | |
| else : | |
| if B - A[i] not in Map : | |
| Map[B - A[i]] = i | |
| return [] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment