It’s also an interview question, from an interview with Youdao Front End.
Write a function to handle the addition of big data. The so-called big data refers to data that exceeds the representation range of conventional data types such as integers and long integers. The implementation language is not limited.
I implemented it using js. Let me talk about my own ideas:
1. First of all, the most important part of this question is how to store big data? What data type should be used to save it? The simplest and feasible way is String
2. After determining what type to use to save the data, the problem becomes clear. First, determine the length of the two incoming strings, take the shortest len loop, add the corresponding bits starting from the low bit, and pay attention to saving the carry. After the short data is processed, the carry is handed over to the remaining part of the longer string for processing.
Look at the code for detailed implementation. For a complete example, see jsfiddle