Leetcode number Subtraction by Fangkaigen number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.