Skip to content

Commit 61edc42

Browse files
committed
动态规划的整理
1 parent cee1697 commit 61edc42

File tree

3 files changed

+424
-2
lines changed

3 files changed

+424
-2
lines changed

24.两两交换链表中的节点.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ def swapPairs(self, head):
3737
:type head: ListNode
3838
:rtype: ListNode
3939
"""
40-
40+
front=ListNode(0)
41+
front.next=head
42+
newhead=front
43+
while front.next and front.next.next: #成对就交换,有落单的不用管
44+
a=front.next
45+
b=a.next
46+
front.next,b.next,a.next=b,a,b.next #逗号表达式的原理是,右边一起打包存入一个新元组,然后给右边,因此不用担心顺序问题
47+
48+
front=a #更新front
49+
return newhead.next
50+

43.字符串相乘.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def multiply(self, num1, num2):
4242
:type num2: str
4343
:rtype: str
4444
"""
45-
45+
return str(eval(num1+'*'+num2))
4646

0 commit comments

Comments
 (0)