Attention needs to be paid to overflow, especially the integer.min_value number.
The dichotomy needs to be mastered.
Divide without division, the powers of divide and conquer
2. Add the Numbers
You are given, linked lists representing, and non-negative numbers. The digits is stored in reverse order and all of their nodes contain a single digit. ADD the numbers and return it as a linked list.
Input: (2, 4, 3) + (5, 6, 4)
Output:7, 0, 8
Basically equals merge array, remember to add carry bit at last.
There is no need to consider overflow, but remember to output 0 instead of an empty list when entering two empty lists.
Divide-Integers
Divide-integers without using multiplication, division and mod operator.
If It is overflow, return max_int.
You cannot use division to divide, so that the divisor is multiplied by two until it is greater than dividend.
The core code is as follows:
while (x >= y) { int a = 0; while (x >= (y << a)) { a+ +; } A--; + = (long) 1 << a ; -= y << A; }
where x is the divisor, y is the divisor, and in this code, you need to note that x, Y is a long. 1 to be cast to long
This problem has a lot of corner case, specifically see
[Leetcode] 29. Divide integers
Multiply Strings
Given numbers represented as strings, return multiplication of the numbers as a string.
Note:
- The numbers can arbitrarily large and is non-negative.
- Converting the input string to integer are not allowed.
- You should don't use internal library such as BigInteger.
- According to my current solution there is no corner case to consider, as long as the output number in front of the extra 0 to remove it. But now the solution is relatively slow. You can improve it when you are free.
Pow (x, N)
Implement Pow (x, n).
1.0 of the 0-time party is 1
2. Determine if x is 0,n whether 0,x is 1
3. Judge the positive and negative of x, and determine the positive and negative of N.
4. Note that n is the case of Integer.min_value, in which case the absolute value is overflow
Btw,double.min_value defines the minimum positive number that is greater than 0 Oh ~
Leetcode TestCase is not related to double overflow, double overflow directly return to Max_value?
Leetcode number Subtraction by Fangkaigen number