博客
关于我
002. Add Two Numbers
阅读量:122 次
发布时间:2019-02-27

本文共 1110 字,大约阅读时间需要 3 分钟。

??????????????????????????????????????????????????

????

  • ???????????????????????????????
  • ??????????????????
  • ???????????????????????????????????
  • ???????????????????????????????????????
  • ??????????????????????
  • ???????????????????????
  • ?????????????????????????????
  • ????

    class Solution:    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:        dummy = ListNode(0)        current = dummy        carry = 0        while l1 or l2:            num1 = l1.val if l1 else 0            num2 = l2.val if l2 else 0            total = num1 + num2 + carry            carry = total // 10            current.next = ListNode(total % 10)            current = current.next            if l1:                l1 = l1.next            if l2:                l2 = l2.next        if carry:            current.next = ListNode(carry)        return dummy.next

    ????

    • ????dummy ????????????????????????
    • ?????while l1 or l2 ???????????????
    • ???????num1 ? num2 ???????????????0?total ????????????
    • ??????current.next ???????????????
    • ??????? l1 ? l2 ????????????????????
    • ?????????????????????????

    ???????????????????????????????????????

    转载地址:http://sojb.baihongyu.com/

    你可能感兴趣的文章
    Netty:原理架构解析
    查看>>
    Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
    查看>>
    Network Sniffer and Connection Analyzer
    查看>>
    Network 灰鸽宝典【目录】
    查看>>
    Networkx写入Shape文件
    查看>>
    NetworkX系列教程(11)-graph和其他数据格式转换
    查看>>
    Networkx读取军械调查-ITN综合传输网络?/读取GML文件
    查看>>
    network小学习
    查看>>
    Netwox网络工具使用详解
    查看>>
    Net与Flex入门
    查看>>
    net包之IPConn
    查看>>
    net发布的dll方法和类显示注释信息(字段说明信息)[图解]
    查看>>
    Net操作Excel(终极方法NPOI)
    查看>>
    Net操作配置文件(Web.config|App.config)通用类
    查看>>
    Net连接mysql的公共Helper类MySqlHelper.cs带MySql.Data.dll下载
    查看>>
    NeurIPS(神经信息处理系统大会)-ChatGPT4o作答
    查看>>
    neuroph轻量级神经网络框架
    查看>>
    Neutron系列 : Neutron OVS OpenFlow 流表 和 L2 Population(7)
    查看>>
    NEW DATE()之参数传递
    查看>>
    New Relic——手机应用app开发达人的福利立即就到啦!
    查看>>