371. Sum of Two Integers
来源:互联网 发布:大华sdk java二次开发 编辑:程序博客网 时间:2024/05/16 10:23
Calculate the sum of two integers a and b, but you are not allowed to use the operator +
and -
.
Example:
Given a = 1 and b = 2, return 3.
预备知识:
整数在计算机中的表示方法(信息存储):
有符号数:既包括正数负数零;
计算机中表示有符号数最常见的方法就是补码形式:将字的最高有效位解释为负权。
while x,y>0,z<0, positive overflow;
while x,y<0,z>0, negative overflow,
class Solution {public: int getSum(int a, int b) { int sum=a^b; int c=a&b; while(c) { a=c<<1; b=sum; sum=a^b; c=a&b; } return sum; }};并没有考虑溢出情况的存在,不清楚内置的+-是否存在溢出检测。
if(x>0&&y>0&&z<0) return erro("positive overflow");if(x<0&&y<0&&z>0) return erri("negetive overflow");
阅读全文
0 0
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 【ionic】卡片制作
- Docker 官方镜像加速 registry.docker-cn.com
- sprintf 补足小数点后两位
- qt-vs 常量中有换行符
- Android Bottom Sheet详解之BottomSheetBehavior与BottomSheetDialog
- 371. Sum of Two Integers
- 不想成为好leader的程序猿不是好攻城狮
- 运行时异常之运行时权限
- 【LeetCode】9. Palindrome Number
- Qt dialog 对话框
- 管理ceph的pool(快照,回滚)
- CoreML实现的MobileNet
- Android常见问题
- puppet 安装与配置