2 Star 1 Fork 0

royce li/Leetcode_royce

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
addTwoNumbers.py 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
Royce Li 提交于 2021-05-10 16:39 . 2020/5/10 First Commit
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
resulthead=result=ListNode(0)
while l1 is not None or l2 is not None :
temp=l1.val if l1 is not None else 0
temp+=l2.val if l2 is not None else 0
result.val+=temp;
if result.val>=10:
result.next=ListNode(1)
result.val=result.val-10
elif l1.next is not None or l2.next is not None:
result.next=ListNode(0)
l1=l1.next if l1 is not None else None
l2=l2.next if l2 is not None else None
result=result.next
return resulthead
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/royce-li/leetcode_royce.git
git@gitee.com:royce-li/leetcode_royce.git
royce-li
leetcode_royce
Leetcode_royce
master

搜索帮助