A + B Problem
来源:互联网 发布:ubuntu服务器重装系统 编辑:程序博客网 时间:2024/05/22 11:33
For given numbers a and b in function aplusb, return the sum of them.
注意
You don't need to parse the input and output. Just calculate and return.
样例
If a=1 and b=2 return 3
挑战
Can you do it with out + operation?
说明
Are a and b both 32-bit integers?
- Yes.
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) { while ((a & b) > 0) {if (a < 0)a--;if (b < 0)b--;int x = (a ^ b);int y = (a & b) << 1;a = x < 0 ? x + 1 : x;b = y < 0 ? y + 1 : y;}return a | b; }};
0 0
- problem 1000: A+B problem
- Problem 1000 A+B Problem
- Problem - 1000 A + B Problem
- A + B Problem
- A + B Problem
- 1000 A+B Problem
- 1001 A + B Problem
- A+B Problem
- 1000 A+B Problem
- A + B Problem
- A + B Problem
- 1000 A + B Problem
- 1000 A+B Problem
- A + B Problem
- A + B Problem II
- A + B Problem II
- POJ1001 -- A-B Problem
- A + B problem II
- Flume-NG指令集和第一个简单的案例
- 设置session过期时间
- win8 virtualbox ubuntu lsubs 不显示硬件usb设备
- 奇异值分解(SVD)原理详解及推导
- EHCI,OHCI,UHCI概念及区别
- A + B Problem
- 社説 20150123 邦人人質事件 国際連携で救出策を探りたい
- BroadcastReceiver广播接收者(六)——粘性广播(StickyBroadcast)使用示例
- LayeredCacheException: MDS-00197
- LeetCode OJ 之 Word Ladder II (字梯 - 二)
- 根据存储过程包含某个关键字,查找相关所有存储过程信息及根据多个主键删除重复列
- 创建firefox profile并用selenium1/selenium2启动
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- 【设计模式学习笔记四】【创建型模式】【单例模式(Singleton)】