Divide Two Integers
来源:互联网 发布:淘宝排名优化教程 编辑:程序博客网 时间:2024/06/06 14:03
注意的几点
1.int 类型溢出问题
2.正负数问题
class Solution {public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int main() function long long ret=0,tmp=0,num=1; bool sign=true; if(dividend>0&&divisor<0||dividend<0&&divisor>0) sign=false; long long x=dividend,y=divisor; x=abs(x);y=abs(y); while(x>=y){ num=y; tmp=1; while(x>=num){ num=(num<<1); tmp=tmp<<1; } num=num>>1; tmp=tmp>>1; x-=num; ret+=tmp; } return sign?ret:-ret; }};
- LeetCode: Divide Two Integers
- [LeetCode]Divide Two Integers
- LeetCode: Divide Two Integers
- [LeetCode] Divide Two Integers
- Divide Two Integers
- Divide Two Integers
- LeetCode28:Divide Two Integers
- [Leetcode] Divide Two Integers
- LeetCode Divide Two Integers
- Divide Two Integers
- 【leetcode】Divide Two Integers
- Divide Two Integers
- Divide Two Integers
- [LeetCode]Divide Two Integers
- Divide Two Integers
- LeetCode-Divide Two Integers
- Divide Two Integers
- 25 - Divide Two Integers
- 新浪微博开发文档
- 友情链接
- 《植物大战僵尸2》中国区上架了
- Javascript 中的 Prototype属性
- SQL中distinct的用法
- Divide Two Integers
- 双向链表
- 通过程序来判断系统大小端问题
- freebsd su root 登陆(su:sorry的解决办法)
- 【题解】【NOIP2012】Vigenère 密码 ←2013.8.1日作业
- hdu 1856 More is better(并查集)
- 配置php.ini路径
- ARP表、交换机转发表、路由表
- Android安卓拍照点击保存后无法返回