首页 > 其他 > 详细

**leetcode笔记--4 Sum of Two Integers

时间:2016-09-26 20:10:47      阅读:209      评论:0      收藏:0      [点我收藏+]

question:

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

my wrong answer

技术分享

错误点:

显示memory error 应该是运行较大数字时导致内存不够,所以这种方法不佳

正确答案地址:(暂时不明白)

http://blog.csdn.net/mebiuw/article/details/51788817

http://www.cnblogs.com/la0bei/p/5659829.html

技术分享

 

重点(补充):

1 合并两个list的方法:

除了直接相加(生成新的list),还有两种方法(修改其中一个list):

用list的extend方法,L1.extend(L2),该方法将参数L2的全部元素添加到L1的尾部,例如:

>>> L1 = [1, 2, 3, 4, 5]
>>> L2 = [20, 30, 40]
>>> L1.extend(L2)
>>> L1
[1, 2, 3, 4, 5, 20, 30, 40]

切片(slice)操作,L1[len(L1):len(L1)] = L2和上面的方法等价,例如:(此方法更加灵活)

>>> L1 = [1, 2, 3, 4, 5]
>>> L2 = [20, 30, 40]
>>> L1[len(L1):len(L1)] = L2
>>> 
>>> L1
[1, 2, 3, 4, 5, 20, 30, 40]

 

**leetcode笔记--4 Sum of Two Integers

原文:http://www.cnblogs.com/qicaide/p/5910311.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!