Posts Tagged 【Math】
来源:互联网 发布:知乎led灯化妆镜 编辑:程序博客网 时间:2024/05/16 13:40
Divide Two Integers
Total Accepted: 34460 Total Submissions: 225991My SubmissionsDivide two integers without using multiplication, division and mod operator.
If it is overflow, return MAX_INT.
//Submission Result: Time Limit Exceededpublic class Solution { public long divide(int dividend, int divisor) { if(divisor == 0) return Integer.MAX_VALUE; int dividendAbs = Math.abs(dividend); long sum = Math.abs(divisor), i = 0,getValue = 1; while(sum<=dividendAbs) { sum+=sum; i++; } if(i == 0) return 0; getValue<<=--i; sum>>=1; while(sum < dividendAbs) { getValue++; sum+=divisor; } if(sum>dividendAbs) getValue--; return (dividend <= 0 && divisor >0 || dividend >= 0 && divisor <0) == true?-getValue:getValue; }}
Have you met this question in a real interview?
0 0
- Posts Tagged 【Math】
- Posts Tagged 【math】Count Primes
- Posts Tagged 【math】Happy Number
- Posts Tagged 【math】Valid Sudoku
- Posts Tagged 【math】Sudoku Solver
- Posts Tagged 【math】Max Points on a Line
- Posts Tagged ‘多站’
- Posts Tagged 【dfs】 Combinations
- Posts Tagged 【tree && dfs】
- Posts Tagged 【String】
- Posts Tagged 【Array】
- Posts Tagged 【Search】
- Posts Tagged 【Catalan】
- Posts Tagged 【List】Anagrams
- POSTS TAGGED: A/B TEST
- Posts Tagged 【fsm】 Valid Number
- Posts Tagged 【dfs】Generate Parentheses
- Posts Tagged 【dp】Interleaving String
- 87. Scramble String Leetcode Python
- eclipse更新插件plugin之后如何clean使之生效
- 网络编程 ——socket基本概念
- Filco蓝牙键盘在Win8.1/Linux双系统中应用 Win8引导Linux 蓝牙双系统配对
- Dynamics CRM 2015 Update 0.1 - Error.ActionFailed Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAc
- Posts Tagged 【Math】
- Linux 目录结构说明
- 涉足计算机视觉领域要知道的
- 探讨在项目中如何处理错误信息
- 矩阵链相乘(递归、动态规划解法)
- Hessian源码学习(1)
- hznu 1652 能量项链(dp,难)
- LeetCode 169 Majority Element
- 如何查看网站的访问量?查看访问量的二个主要方法【站长之家的SEO综合查询工具】