-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
48 lines (32 loc) · 833 Bytes
/
Copy pathtest.py
File metadata and controls
48 lines (32 loc) · 833 Bytes
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
42
43
44
45
def two_sum(li, target):
map = {}
for i, elem in enumerate(li):
diff = target - elem
if diff in map:
return [i, map[diff]]
map[elem] = i
return []
print(two_sum([1, 2, 3, 4, 5, 6, 7, 8], 14))
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def dist(self, p):
return abs(p.x - self.x) + abs(p.y - self.y)
def print(self):
print(f"({self.x}, {self.y})")
def valid_parenthesis(s):
stack = []
for char in s:
if char == '(':
stack.append('(')
elif char == ')' and len(stack) != 0:
stack.pop()
else:
return False
return len(stack) == 0
p1 = Point(1, 5)
p2 = Point(5, 1)
print(p2.dist(p1))
print(valid_parenthesis("((())()(()))"))
print("yo")