- 浏览: 89449 次
- 性别:
- 来自: 南京
最新评论
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.
不用*, /, %来实现除法。
注意:1.正负号;2.INT_min=-2147483648,变为正数越界。
const int INTMIN = -2147483648; class Solution { public: int divide(int dividend, int divisor) { if (divisor == INTMIN) return dividend == INTMIN ? 1 : 0; if (divisor < 0) return -divide(dividend, -divisor); if (dividend == INTMIN) return -1-divide(-divisor-dividend, divisor); if (dividend < 0) return -divide(-dividend, divisor); if (dividend < divisor) return 0; int d, s, rd, rs; d = rd = divisor; s = rs = 1; while (d << 1 > 0 && d << 1 < dividend) { s <<= 1; d <<= 1; } return s + divide(dividend - d, divisor); } };
发表评论
-
[Leetcode] Gas Station
2013-10-07 00:02 929Gas Station AC Rate: 101 ... -
[Leetcode] Word Break 1 & 2
2013-10-05 23:26 1376Word Break AC Rate: 2/1 ... -
[Leetcode] Single Number 1 & 2
2013-10-05 22:50 2765Single Number AC Rat ... -
[Leetcode] Copy List with Random Pointer
2013-10-05 22:43 587Copy List with Random Pointe ... -
[Leetcode] Path Sum
2013-10-03 23:52 599Path Sum AC Rate: 87 ... -
[Leetcode] Remove Duplicates from Sorted List 1 & 2
2013-10-03 23:34 981Remove Duplicates from Sort ... -
[Leetcode] Scramble String
2013-10-03 16:55 1843Scramble String AC Rate ... -
[Leetcode] Partition List
2013-09-29 23:38 670Partition List AC Rate: ... -
[Leetcode] Word Search
2013-09-21 23:21 861Given a 2D board and ... -
[Leetcode] Decode Ways
2013-09-11 17:33 692Decode WaysJun 25 '126747 / 2 ... -
[Leetcode] Convert Sorted List to Binary Search Tree
2013-09-11 16:06 722Convert Sorted List to Binary ... -
[Leetcode] Binary Tree Level Order Traversal
2013-09-10 14:39 787Binary Tree Level Order Trave ... -
[Leetcode] Subsets 1 ^& 2
2013-09-09 21:42 876SubsetsApr 18 '126226 / 1626 ... -
[Leetcode] Unique Paths II
2013-09-09 21:10 768Unique Paths IIMar 29 '124573 ... -
[Leetcode] Flatten Binary Tree to Linked List
2013-09-09 02:35 731Flatten Binary Tree to Linked ... -
[Leetcode] Triangle
2013-09-04 16:32 934TriangleOct 30 '126503 / 1779 ... -
[Leetcode] Balanced Binary Tree
2013-08-27 20:53 614Balanced Binary TreeOct 9 '12 ... -
[Leetcode] Rotate Image
2013-08-22 15:54 980Rotate ImageMar 18 '124182 / ... -
[Leetcode] Permutations / Permutations II
2013-08-22 15:41 2512Permutations IIMar 17 '12494 ... -
[Leetcode] Jump Game / Jump Game II
2013-08-22 10:31 663Jump GameMar 25 '126923 / 162 ...
相关推荐
自己写的一个完整的程序,包括main函数,在VS上面提交通过,但是放到leetcode上面会出现问题;只是作为一个参考,一起学习学习0.o!解决的问题有:第一:两个链表的最后一个值相加后进位的问题;第二:两个链表的...
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return ...
Leetcode two sum java 解法
先来看LeetCode-29上的Divide Two Integers题目要求: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 1 2 3 就是说不用乘法,除法,求模运算...
371 | [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) | [C++](./C++/sum-of-two-integers.cpp) [Python](./Python/sum-of-two-integers.py) | _O(1)_ | _O(1)_ | Easy | LintCode | ...
刷LeetCode刷LeetCode刷LeetCode刷LeetCode刷LeetCode
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where...
答案LeetCode_1_TwoSum LeetCode 问题:给定一个整数数组,找出两个数字,使它们相加为特定的目标数字。 函数 twoSum 应该返回两个数字的索引,使它们相加为目标,其中 index1 必须小于 index2。 请注意,您返回的...
Two-Sum leetcode两数之和代码 题目描述:给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组...
Two Sum II - Input array is sorted LeetCode 344 Reverse String LeetCode 345 Reverse Vowels of a String 2 字符串 编号 题目 LeetCode 3 Longest Substring Without Repeating Characters LeetCode 13 Roman to...
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Java AC版本
vs code LeetCode 插件
大佬的leetcode刷题笔记(c++版本)
leetcode 两分球-1 问题1 () 问题2 () 问题3 ()
leetcode 两分球-2 问题1 () 问题2 () 问题3 ()
leetcode中文版
LeetCode 101_C++_算法_leetcode_leetcode101_leetcode101.zip
Leetcode\TwoSum\TwoSum.cs 问题: 业绩报告: 反转整数 代码: Leetcode\ReverseInteger\ReverseInteger.cs 问题: 业绩报告: 回文数 代码: Leetcode\PalindromeNumber\PalindromeNumber.cs 问题: 从排序数组中...
leetcode leetcode练习 twosum 问题 ;add two numbers问题;reverse integer问题;最大不重复子字符串长度问题;atoi问题;
LeetCode 101_C++_算法_leetcode_leetcode101_leetcode101_源码.zip