Leetcode 2 第一次做 Python
来源:互联网 发布:首届全球程序员节嘉宾 编辑:程序博客网 时间:2024/06/06 03:01
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def addTwoNumbers(self,l1, l2): Levup = 0 new_l = ListNode(0) k = new_l while l1 or l2: new_l.val = (Levup +l1.val+l2.val)%10 Levup = (l1.val + l2.val+Levup)/10 if(l1.next and not l2.next): l1 = l1.next l2 = ListNode(0) elif(l2.next and not l1.next): l2 = l2.next l1 = ListNode(0) elif(not(l1.next or l2.next)): if Levup==0: l1 = None l2 = None else: new_r = ListNode(Levup) new_l.next = new_r break else: l1 = l1.next l2 = l2.next if(l1 or l2): new_r = ListNode(0) new_l.next = new_r new_l = new_l.next new_l = None return k
Python的第二题,做的非常乱效率极低,而且修正了很多次。以后改正,先去学习一下大佬们的代码
0 0
- Leetcode 2 第一次做 Python
- 第一次做面试官2
- 第一次使用python 2
- 第一次做leetcode中Difficulty为easy的题-292
- 第一次在leetcode上做hard级别的题目
- 第一次python,第一次爬虫
- 回顾第一次做网页
- 第一次做Blog
- 第一次做BLOG
- 第一次做hr
- 第一次自己做决定
- 第一次做红烧排骨
- 第一次做topcoder
- 第一次做驴打滚
- 第一次!做博客
- 第一次做沙拉
- 第一次做培训
- 第一次做自己
- ProgressBar进度条
- 成功把pulltorefresh集成进我的studio项目中
- eclipse安装tomcat插件
- Java基础
- ARM汇编基础-存储和加载指令
- Leetcode 2 第一次做 Python
- Android日记-2017.5.11-supportsRtl
- Cookie 的使用方法
- python基础-----反射和eval
- Python爬虫:scrapy安装
- Eclipse中部署项目时,Tomcat启动报错 “Failed to start component [StandardServer[8005]]”的解决
- 在unity中使用Newtonsoft.Json
- 中文乱码问题
- MyEclipse2014安装Activiti插件后 打开BPMN图报错Could not open the editor: Unknowned