**leetcode笔记--4 Sum of Two Integers
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
http://blog.csdn.net/xtj332/article/details/6639009

重点(补充):
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的更多相关文章
- 【一天一道LeetCode】#371. Sum of Two Integers
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Calcula ...
- 通过位运算求两个数的和(求解leetcode:371. Sum of Two Integers)
昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, b ...
- 【LeetCode】371. Sum of Two Integers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 位运算 日期 题目地址:https://leetco ...
- 【leetcode】371. Sum of Two Integers
题目描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...
- LeetCode算法题-Sum of Two Integers(Java实现)
这是悦乐书的第210次更新,第222篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第78题(顺位题号是371).计算两个整数a和b的总和,但不允许使用运算符+和 - .例 ...
- 【Leetcode 371】Sum of Two Integers
问题描述:不使用+是或-操作符进行整数的加法运算 int getSum(int a, int b); 我的思路:把整数化成二进制进行运算,注意类型是int,也就是要考虑负数.关于负数的二进制表示可见之 ...
- LeetCode之371. Sum of Two Integers
---------------------------------- 使用位运算实现加法: a^b 加不同部分(a&b)<<1 加相同部分递归相加 AC代码: public cla ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
随机推荐
- POJ 1830 开关问题 【01矩阵 高斯消元】
任意门:http://poj.org/problem?id=1830 开关问题 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...
- ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(四) 添加表情、群聊功能
休息了两天,还是决定把这个尾巴给收了.本篇是最后一篇,也算是草草收尾吧.今天要加上表情功能和群聊.基本上就差不多了,其他功能,读者可以自行扩展或者优化.至于我写的代码方面,自己也没去重构.好的,我们开 ...
- [转]Android Studio启动时出现unable to access android sdk add-on list
转载请标明出处:http://blog.csdn.net/xx326664162/article/details/50563122 文章出自:薛瑄的博客 你也可以查看我的其他同类文章,也会让你有一定的 ...
- 让IIS支持无后缀名访问
IIS中添加对Mime类型 . application/octet-stream
- 重写viewWillAppear 和 viewWillDisAppear时[super viewWillAppear] 和 [super viewWillDisappear]的调用位置
参考网址:https://stackoverflow.com/questions/3906704/when-should-i-call-super 在写代码的过程中如果重写了viewWillAppea ...
- 序列化表单为json对象,datagrid带额外参提交一次查询 后台用Spring data JPA 实现带条件的分页查询 多表关联查询
查询窗口中可以设置很多查询条件 表单中输入的内容转为datagrid的load方法所需的查询条件向原请求地址再次提出新的查询,将结果显示在datagrid中 转换方法看代码注释 <td cols ...
- Swift_数组详解
Swift_数组详解 点击查看源码 初始化 //初始化 fileprivate func testInit() { //空数组 var array = [Int]() print(array) arr ...
- iframe优缺点
优点:重载页面时不需要重载整个页面,只需要重载页面中的一个框架页(减少了数据的传输,加快了网页下载速度)
- fabricjs 的用途
使用html5 的canvas画板做一些图片旋转,拖动,放大,缩小和合成图片的功能,有没有一个集成好的组件库呢?答案肯定是有的,而且还不止我前面提到的功能,下面介绍一下我使用的fabricjs. 官网 ...
- 2 3 5 7的倍数 (51Nod - 1284)[容斥定理]
20180604 给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 10,只有1不是2 3 5 7的倍数. Input 输入1个数N(1 <= N <= 10^1 ...