题目:两个整数相除
来源:互联网 发布:unity3d控制人物动作 编辑:程序博客网 时间:2024/05/19 13:21
将两个整数相除,要求不使用乘法、除法和 mod 运算符。
如果溢出,返回 2147483647 。
您在真实的面试中是否遇到过这个题?
Yes
样例
给定被除数 = 100 ,除数 = 9,返回 11。
标签 Expand
相关题目 Expand
public class Solution { /** * @param dividend the dividend * @param divisor the divisor * @return the result */ public int divide(int dividend, int divisor) { // Write your code here if(divisor==0) return 0; long count = 0; long absdivident = Math.abs((long)dividend); long absdivisor = Math.abs((long)divisor); while(absdivident>=absdivisor){ absdivident -=absdivisor; count++; } if((dividend<0&&divisor>0)||(dividend>0&&divisor<0)){ count = 0-count; } if(count>Integer.MAX_VALUE||count<Integer.MIN_VALUE){ return Integer.MAX_VALUE; } return (int)count; }}
0 0
- 题目:两个整数相除
- 两个整数相除
- 两个整数相除
- 两个整数相除
- 两个整数相除
- 两个整数相除
- LintCode-两个整数相除
- LintCode_两个整数相除
- Leetcode020--两个整数相除
- 29.两个整数相除
- LintCode:两个整数相除
- 两个整数相除-LintCode
- LintCode 两个整数相除
- 两个整数相除得float
- 求两个整数相除的结果
- Divide Two Integers 两个整数相除
- Java实现两个整数相除
- lintcode(414)两个整数相除
- stepwise算法
- 题目:不同的子序列
- 题目:丑数
- 题目:丢失的第一个正整数
- 实现一个事务多个dao情况下,使用同一个connection,保证线程安全
- 题目:两个整数相除
- 笔记一下动态MST离线的分治做法
- Hbuilder开发app实战-识岁05-Crypto.js实现各种js加密算法
- radiogroup_switch_fragment代替tabhost 效果
- Git学习(二)
- [HDU 5410]CRB and His Birthday[01、完全背包]
- Dom解析XML文件数据
- JavaHttpGet中文内容编码为GBK时注意
- C++: 安装minGW,Msys;对接NeatBeans IDE