divide-two-integers
来源:互联网 发布:淘宝商品加入公益宝贝 编辑:程序博客网 时间:2024/05/21 10:21
题目:
Divide two integers without using multiplication, division and mod operator.
程序:
class Solution {public: int divide(int dividend, int divisor) { long long a = abs((long long)dividend); //负数可以溢出 long long b = abs((long long)divisor); int finalcount=0; while(a >= b){ int count = 1; long sum = b; while(sum + sum <= a){ //普通的减法会超时 sum += sum; count += count; } a -= sum; finalcount += count; }; return (dividend>>31 ^ divisor>>31)? -finalcount:finalcount; }};
阅读全文
0 0
- 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
- openwrt下载问题
- 2017.09.10【NOIP提高组】模拟赛B组
- u_boot和Linux内核之间的参数传递
- 单链表的基本操作,正序/逆序建表(尾插法/头插法)、计算单链表长度、输出单链表内容、插入、删除,给出完整代码
- Tomcat服务器学习和使用(一)
- divide-two-integers
- RxJava学习笔记之线程调度器Scheduler(二)
- 【模板】网络最大流 (Dinic)
- Asp.MVC中几种常用ActionResult
- 博客笔记
- 构造方法重载
- Java内存模型图
- 编号中的数学_KEY
- 数据库事务的四大特性以及事务的隔离级别