A + B Problem
Write a function that add two numbers A and B. You should not use +
or any arithmetic operators.
分析:
典型的Bit Operation.
class Solution {
/*
* param a: The first integer
* param b: The second integer
* return: The sum of a and b
*/
public int aplusb(int a, int b) {
if (a == ) return b;
int sum = a ^ b;
int carry = (a & b) << ;
return aplusb(carry, sum);
}
};
A + B Problem的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- java的RMI(Remote Method Invocation)
RMI 相关知识RMI全称是Remote Method Invocation-远程方法调用,Java RMI在JDK1.1中实现的,其威力就体现在它强大的开发分布式网络应用的能力上,是纯Java的网络 ...
- oracle 的安装脚本
==[root@oracle ~]# cat 1.preusers.sh ==#!/bin/bash#Purpose:Create 3 groups named 'oinstall','dba','o ...
- MVC学习Day01
~~~~ =============================================================================================== ...
- .net架构设计读书笔记--第二章 设计体系结构
第五节 探索领域架构 一.领域驱动设计的价值与意义 最初在java中使用,.net要晚些才引入.领域驱动设计出现之初的争议.一个向导,少走弯路 1. 我们真的需要DDD吗? DDD并不适用于每个软 ...
- 学习笔记 BIT(树状数组)
痛定思痛,打算切割数据结构,于是乎直接一发BIT 树状数组能做的题目,线段树都可以解决 反之则不能,不过树状数组优势在于编码简单和速度更快 首先了解下树状数组: 树状数组是一种操作和修改时间复杂度都是 ...
- 最短路之Dijkstra算法
1. 邻接矩阵 int cost[MAX_V][MAX_V]; //assume cost[u][v]>0 int d[MAX_V]; bool used[MAX_V]; void Dijkst ...
- HDU 1054 Strategic Game(最小点覆盖+树形dp)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 ...
- html标签(一)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 四层负载均衡——LVS
LVS 参考:http://zh.linuxvirtualserver.org/ 几个术语: Director:也可以称为调度器,LVS前端设备: realserver:也称为真实内部服务器, ...
- MySql开启事务
CREATE PROCEDURE test_sp1( ) BEGIN ; ; START TRANSACTION; INSERT INTO test VALUES(NULL, 'test sql 00 ...