V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
334862132
V2EX  ›  Python

Python 小白求助 leetcode 链表第二个如何调试阿

  •  
  •   334862132 · 2019-09-15 20:59:09 +08:00 · 1660 次点击
    这是一个创建于 1656 天前的主题,其中的信息可能已经有所发展或是发生改变。

    结题思路就不上传了,都是网上抄的,但是在 leetcode 上能通过 在本地就运行不了是什么原因,传入的到底是什么值阿? l1 = [2,3,4] l2 = [5,6,4] res = Solution().addTwoNumbers(l1, l2) print(res)

    class ListNode: def init(self, x): self.val = x self.next = None

    class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ lret = ListNode(0) carryNum = 0 iterNode = lret iterL1 = l1 iterL2 = l2 while True: number = (iterL1.val if iterL1 else 0) + (iterL2.val if iterL2 else 0) + carryNum stopNum = number % 10 carryNum = number / 10 iterNode.val = stopNum iterL1 = iterL1.next if iterL1 else None iterL2 = iterL2.next if iterL2 else None if not iterL1 and not iterL2 and carryNum == 0: break else: nextNode = ListNode(0) iterNode.next = nextNode iterNode = nextNode return lret

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2767 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 12:12 · PVG 20:12 · LAX 05:12 · JFK 08:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.