LintCode 1.A+B的问题

描述

给出两个整数 ab , 求他们的和。

答案

public class Solution {
/**
* @param a: An integer
* @param b: An integer
* @return: The sum of a and b
*/
public int aplusb(int a, int b) {
// write your code here
int m = a^b; // 保留值不同的位
int n = (a&b) << 1; // 值相同的位进1
if(n != 0) {
m = aplusb(m, n);
}
return m;
}
}

LintCode 1.A+B的问题的更多相关文章

  1. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  2. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

  3. Lintcode 85. 在二叉查找树中插入节点

    -------------------------------------------- AC代码: /** * Definition of TreeNode: * public class Tree ...

  4. Lintcode 166. 主元素

    ----------------------------------- Moore's voting algorithm算法:从一个集合中找出出现次数半数以上的元素,每次从集合中去掉一对不同的数,当剩 ...

  5. Lintcode 166. 链表倒数第n个节点

    ----------------------------------- 最开始的想法是先计算出链表的长度length,然后再从头走 length-n 步即是需要的位置了. AC代码: /** * De ...

  6. Lintcode 157. 判断字符串是否没有重复字符

    ------------------------ 因为字符究竟是什么样的无法确定(比如编码之类的),恐怕是没办法假设使用多大空间(位.数组)来标记出现次数的,集合应该可以但感觉会严重拖慢速度... 还 ...

  7. Lintcode 175. 翻转二叉树

    -------------------- 递归那么好为什么不用递归啊...我才不会被你骗...(其实是因为用惯了递归啰嗦的循环反倒不会写了...o(╯□╰)o) AC代码: /** * Definit ...

  8. Lintcode 372. O(1)时间复杂度删除链表节点

    ----------------------------------- AC代码: /** * Definition for ListNode. * public class ListNode { * ...

  9. Lintcode 469. 等价二叉树

    ----------------------------------------------- AC代码: /** * Definition of TreeNode: * public class T ...

  10. Lintcode 375.克隆二叉树

    -------------------------- 水题 AC代码: /** * Definition of TreeNode: * public class TreeNode { * public ...

随机推荐

  1. 点击按钮如何改变当前窗口的url

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. pkg-config 详解

    转载自:https://blog.csdn.net/newchenxf/article/details/51750239 1 什么是pkg-config pkg-config是一个linux下的命令, ...

  3. FPGA小例子

    AND ---与门:OR --- 或门:INV --- 非门:NAND --- 与非门:NOR --- 或非门:XOR --- 异或门:XNOR ---同或门:MUX --- 数据选择器: 1.使用一 ...

  4. redis基础2

  5. xcode10对应的xcode command line tool编译的坑

    众所周知,xcode10新增的编译系统new build system会不支持一些老项目的编译,一般的做法是在Xcode编译配置Xcode->File->Project Settings/ ...

  6. 2019春第五周作业Compile Summarize

    这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 在这里 我在这个课程的目标是 能够精通关于数组内部运作原理 这个作业在哪个具体方面帮助我实现目标 如何输出一行的连续字符 参考文献与网址 ...

  7. ORA-27104: system-defined limits for shared memory was misconfigured与Linux内核参数配置有关的案例

    ```[oracle@WWJD01 ~]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Fri Sep 21 15:1 ...

  8. NodeMan介绍

    近年来,随着nodejs的突飞猛进,node项目数量增长迅猛,node项目完美的阐释了“开箱即用”的理念.小到创业公司,大到阿里这样的巨头,背后均有node的身影. node项目基于Chrome的V8 ...

  9. java支付宝接口开发

    在线支付接入支付宝,首先需要去官网申请开发者账号,具体步骤如下: 一.打开官网 1.直接打开链接https://open.alipay.com/platform/home.htm进入 2.百度搜索蚂蚁 ...

  10. 在Ubuntu16.04中python环境下实现tab键补全

    1.编写tab.py的代码: 1 #!/usr/bin/env python 2 # python startup file 3 import sys 4 import readline 5 impo ...