Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
python-algorithm
提交
968a311c
P
python-algorithm
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
python-algorithm
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
python-algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
968a311c
编写于
1年前
作者:
Kwan的解忧杂货铺@新空间代码工作室
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:键盘问题
上级
09a03eb2
main
无相关合并请求
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
2 deletion
+66
-2
.idea/misc.xml
.idea/misc.xml
+1
-1
.idea/python-algorithm.iml
.idea/python-algorithm.iml
+1
-1
02-链表/problem_solving_02.py
02-链表/problem_solving_02.py
+64
-0
未找到文件。
.idea/misc.xml
浏览文件 @
968a311c
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.9 (py
36tf1
)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.9 (py
thon-algorithm
)"
project-jdk-type=
"Python SDK"
/>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.idea/python-algorithm.iml
浏览文件 @
968a311c
...
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.9 (py
36tf1
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.9 (py
thon-algorithm
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
02-链表/problem_solving_02.py
0 → 100644
浏览文件 @
968a311c
"""
两数相加 II
"""
from
typing
import
List
,
Optional
class
ListNode
:
def
__init__
(
self
,
val
=
0
,
next
=
None
):
self
.
val
=
val
self
.
next
=
next
# 翻转链表
def
reverseList
(
head
:
ListNode
)
->
ListNode
:
pre
=
None
curr
=
head
while
curr
:
next
=
curr
.
next
curr
.
next
=
pre
pre
=
curr
curr
=
next
return
pre
class
Solution
:
def
addTwoNumbers
(
self
,
l11
:
Optional
[
ListNode
],
l22
:
Optional
[
ListNode
])
->
Optional
[
ListNode
]:
l1
=
reverseList
(
l11
)
l2
=
reverseList
(
l22
)
res
=
ListNode
(
0
)
cur
=
res
carry
=
0
while
l1
or
l2
:
x
=
l1
.
val
if
l1
else
0
y
=
l2
.
val
if
l2
else
0
s
=
x
+
y
+
carry
carry
=
s
//
10
cur
.
next
=
ListNode
(
s
%
10
)
cur
=
cur
.
next
if
l1
:
l1
=
l1
.
next
if
l2
:
l2
=
l2
.
next
if
carry
:
cur
.
next
=
ListNode
(
carry
)
return
reverseList
(
res
.
next
)
if
__name__
==
'__main__'
:
l1
=
ListNode
(
7
)
l1
.
next
=
ListNode
(
2
)
l1
.
next
.
next
=
ListNode
(
4
)
l1
.
next
.
next
.
next
=
ListNode
(
3
)
# l1.next.next.next.next = ListNode(9)
# l1.next.next.next.next.next = ListNode(9)
# l1.next.next.next.next.next.next = ListNode(9)
l2
=
ListNode
(
5
)
l2
.
next
=
ListNode
(
6
)
l2
.
next
.
next
=
ListNode
(
4
)
# l2.next.next.next = ListNode(9)
result
=
Solution
().
addTwoNumbers
(
l1
,
l2
)
while
result
:
print
(
result
.
val
,
end
=
' -> '
)
result
=
result
.
next
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部