Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
题目的意思就是把这个数组代表的大数字加一,然后考虑进位的问题,如果都是9就要考虑加一位的问题。这是一个处理大数据的办法,当数字超出了整型的长度,我们就可以用这种办法。我们需要处理的就是进位问题。
public int[] plusOne(int[] digits) {
int flag = 1, sum;
for (int i = digits.length - 1; i >= 0;

该博客介绍了LeetCode第66题的解决方案,即如何对一个由数组表示的非负大数字加一。文章讨论了在处理数字进位时的策略,特别是当数组中的所有元素均为9时如何进行进位操作,同时提出通过检查每个元素是否为9来简化算法的思路。
订阅专栏 解锁全文
280

被折叠的 条评论
为什么被折叠?



