**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 ...
随机推荐
- Python 函数作为返回值
函数作为返回值高阶函数除了可以接收函数作为参数外,还可以把函数作为结果值返回. def lazy_sum(*args): def sum(): ax=0 for n in args: ax = ax ...
- POJ Air Raid 【DAG的最小不相交路径覆盖】
传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- ms17_010利用复现(32位)
准备阶段: 1,原版windows7:cn_windows_7_enterprise_x86_dvd_x15-70737.iso 2,kali系统, 虚拟机 3,用于32位机的攻击模块:Eterna ...
- 教你用SingalR实现后台开发程序运行时时检测
在调试js的时候都喜欢用console.log输出相应的运行结果或者查看变量值,以便于调试程序bug,可是程序后台代码运行的时候,本地没有问题,线上代码有问题怎么办呢,写日志是一个办法,可是有没有更直 ...
- java实现权重随机算法
权重随机算法在抽奖,资源调度等系统中应用还是比较广泛的,一个简单的按照权重来随机的实现,权重为几个随机对象(分类)的命中的比例,权重设置越高命中越容易,之和可以不等于100: 简单实现代码如下: im ...
- mybais学习记录一——入门程序
一.传统连接数据库和执行sql的不足 1.数据库连接,使用时就创建,不使用立即释放,对数据库进行频繁连接开启和关闭,造成数据库资源浪费,影响 数据库性能. 设想:使用数据库连接池管理数据库连接. 2. ...
- 学大伟业 Day 1 培训总结
第一天培训,讲的基本算法,东西很多.还有些数论,图论,数据结构and some small tricks 一.输入输出技巧 //输入输出技巧 /* scanf.printf:速度快,需要记忆不同数据类 ...
- C#提取html中的汉字
using System.Text.RegularExpressions; private string StripHT(string strHtml) //从html中提取纯文本 { Regex r ...
- bzoj2982: combination(lucas)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- 转:java23种设计模式
以下是学习过程中查询的资料,别人总结的资料,比较容易理解(站在各位巨人的肩膀上,望博主勿究) 概述 设计模式是针对某一类问题的最优解决方案,是从许多优秀的软件系统中总结出的. Java中设计模式(ja ...