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的更多相关文章

  1. 【一天一道LeetCode】#371. Sum of Two Integers

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Calcula ...

  2. 通过位运算求两个数的和(求解leetcode:371. Sum of Two Integers)

    昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, b ...

  3. 【LeetCode】371. Sum of Two Integers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 位运算 日期 题目地址:https://leetco ...

  4. 【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 - ...

  5. LeetCode算法题-Sum of Two Integers(Java实现)

    这是悦乐书的第210次更新,第222篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第78题(顺位题号是371).计算两个整数a和b的总和,但不允许使用运算符+和 - .例 ...

  6. 【Leetcode 371】Sum of Two Integers

    问题描述:不使用+是或-操作符进行整数的加法运算 int getSum(int a, int b); 我的思路:把整数化成二进制进行运算,注意类型是int,也就是要考虑负数.关于负数的二进制表示可见之 ...

  7. LeetCode之371. Sum of Two Integers

    ---------------------------------- 使用位运算实现加法: a^b 加不同部分(a&b)<<1 加相同部分递归相加 AC代码: public cla ...

  8. 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 ...

  9. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

随机推荐

  1. 【[AHOI2006]文本编辑器】

    题目 多了区间翻转,之后没了 区间翻转的标记记得在\(kth\)的时候下传 代码 #include<algorithm> #include<iostream> #include ...

  2. Oracle连接问题

    ORA-01034: ORACLE not availableORA-27101: shared memory realm does not exist sqlplus /nolog conn /as ...

  3. sublime重构变量

    选中变量后按下Ctrl+D可批量修改变量名

  4. 随机森林算法-Deep Dive

    0-写在前面 随机森林,指的是利用多棵树对样本进行训练并预测的一种分类器.该分类器最早由Leo Breiman和Adele Cutler提出.简单来说,是一种bagging的思想,采用bootstra ...

  5. readonly disabled

    $("#cpeIdInput").attr('disabled',false);  //禁用之后数据提交不到后台(IE),解决方法在点击按钮时禁用,想办法在提交之前(beforeS ...

  6. c语言描述的静态查找表

    顺序表的查找: 直接循环依次和目标比较就行 有序表的查找(二分查找): int search(SS *T,Type key){ int mid; ; int high=T.length; while( ...

  7. 转载:Python中的if __name__ == '__main__'

    刚开始学习Python时,对于有些书出现的函数带有“if __name__ == '__main__'”总是迷惑不解,比如<dive into Python>中开头的哪个根据输入的数字计算 ...

  8. Showing All Messages : error: open /Users/apple/Library/Developer/Xcode/DerivedData/xxx-dkhmpttmnuppvbcxijlcxacfpzcl/Build/Products/Debug-iphoneos/xxx.app/EaseUIResource.bundle/arrow@2x.png: N

    2报错 Showing All Messages : error: open /Users/apple/Library/Developer/Xcode/DerivedData/xxx-dkhmpttm ...

  9. 背景qwq

  10. Percona-Tookit工具包之pt-show-grants

      Preface       User privileges regulation is pretty important in DBAs routine job.As we all know,it ...