Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a77937

Browse files
authored
Create 2130-maximum-twin-sum-of-a-linked-list.py
1 parent4742bf3 commit2a77937

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution:
2+
defpairSum(self,head:Optional[ListNode])->int:
3+
slow,fast=head,head
4+
prev=None
5+
whilefastandfast.next:
6+
fast=fast.next.next
7+
tmp=slow.next
8+
slow.next=prev
9+
prev=slow
10+
slow=tmp
11+
12+
res=0
13+
whileslow:
14+
res=max(res,prev.val+slow.val)
15+
prev=prev.next
16+
slow=slow.next
17+
returnres

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp