Two Sigma VO 面试真题解析:大数乘法(Big Number Multiplier)

18次阅读
没有评论

Implement a function that takes numbers a and b in string form and returns the result of a * b as a string.

The input can only contain digits [0-9] or a negative sign, and it can represent arbitrarily large numbers that may not fit in any primitive data type.

You must implement the multiplication algorithm without using any big number library or language built-in feature.

You do not need to worry about invalid input such as letters in the string, leading zeroes, etc.

这道题要求你实现字符串形式的大数乘法:输入的两个数可能远超原生整数范围,因此不能直接转成内置数值类型相乘。标准做法是先处理符号,再把数字部分按十进制位拆开,使用“竖式乘法”的思路用数组累加每一位的部分积,最后统一处理进位并拼回字符串。核心考点是手工模拟乘法过程、正确处理负号以及大整数进位和前导零。

正文完
 0