forked from HarshRangwala/Interview-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum.py
More file actions
55 lines (36 loc) · 1.05 KB
/
TwoSum.py
File metadata and controls
55 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 14 20:05:07 2019
@author: Anuj
"""
#You are given a list of numbers, and a target number k.
#Return whether or not there are two numbers in the list that add up to k.
class Solution:
def twoSum(self, nums, target):
'''
dictionary = {}
for index, num in enumerate(nums):
other = target - num
print(other)
print(dictionary)
print(index)
if other in dictionary:
return True #[dictionary[other], index]
else:
dictionary[num] = index
print("---",dictionary[num])
print("-------",index)
return []
'''
'''
if len(nums)<2:
pass
r = list()
for i in range(len(nums)):
comp = target - nums[i]
print(comp,"=comp",target,"-",nums[i])
print("Value of",r)
if comp in r:
return [i, nums.index(comp)]
r.append(nums[i])
'''