-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds.py
36 lines (34 loc) · 1018 Bytes
/
ds.py
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
#!/usr/bin/env python
#反转列表
class Solution():
def __init__(self):
def reverseList(self, head):
cur, prev = head, None
#while cur:
# cur.next, prev, cur = prev, cur, cur.next
return prev
def swapPairs(self, head):
pre, pre.next = self,head
while pre.ext and pre.next.next:
a=pre.next
b=a.next
pre.next,b.next,a.next = b,a, b.next
pre = a
return self.next
def hasCycle(self, head):
fast = slow = head;
while slow and fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow is fast:
return True
return False
def isValid(self, s):
stack = []
paren_map = {')':'(', ']':'[', '}':'{'}
for c in s:
if c not in paren_map:
stack.append(c)
elif not stack or paren_map[c] != stack.pop():
return False
return not stack