Leetcode Summary--high Precision Chapter

Source: Internet
Author: User
Tags data structures multiply strings what interface
Some of our common basic data structures such as Integer int or float float because too many bits cannot be stored in the built-in type, we need to implement high precision data types for storage and operation. This kind of problem is more practical in the actual product, so it is also a frequent visitor in the interview. In Leetcode, there are several questions about high accuracy:
ADD Binary
ADD two Numbers
Plus One
Multiply Strings

Add Binary and add two Numbers is the same type of problem, are high precision of the addition operation, just a binary, a decimal, in fact, the system is indifferent to the basic code can be unified with a way to achieve. The idea is also very simple, is to add from the low, always maintain the carry on it. is to investigate very basic array operation, there is no difficulty in the algorithm, mainly to see coding implementation capabilities.

Plus One is also a common topic, he is in fact the implementation of C + + in the operator, because only +1, so in fact, than the above problem is simpler. The small trap of this problem is that it is stored with arrays from high to low, so if there is a carry, then you need to redistribute space, and give the highest bit 1, and the other bits will be 0. Here comes a point where high precision storage should be low to high storage or vice versa, which is a question that may be asked in an interview.

Multiply Strings This problem is a high-precision multiplication, is more complex, the need for each of the results of the calculation of the cumulative, which is a little more detail, here is not detailed, personally think that the implementation of a bit complex, is not very suitable for the interview to appear.

Although the topic is not much, but the occurrence rate of such topics is very high, the main reason is not that the subject itself has a lot of test sites, but they are particularly good expansion, basically asked this topic, first of all, to examine the coding ability, in general, this is the subtraction operation, The next step will be the design of data structures (or object-oriented). These topics themselves are for High-precision BigInteger service, the interviewer will ask questions about the design of the data structure, for example, if you want to design this class, what data structure to use (such as arrays or lists, what pros and cons), what interfaces (constructors, subtraction operations, etc.) are needed. And, for example, to design a constructor, what interface constructors are needed (here assignment constructors, assignment operators these are definitely needed, but be aware that you must provide interfaces for general types such as Int,long, a good high-precision class must be compatible with its weaker data structure). Above I listed some may be in the interview will continue to examine the question, also is part of the association, like this design question may ask or is quite many, is also very common, everybody can carry on this question's preparation and the association Kazakhstan.

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.