LeetCode66: Plus one


Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.


意思是用一个数组来表示一个非负整数(比如100就表示为[1,0,0]),然后把这个整数的值加1,返回一个表示这个数的数组。唯一需要注意的地方就是当某一位为9时,而又需要加1时,要考虑进位,进位的方法就是设置当前值为0,然后把这个1往当前数的前一位上加。如果已经到最高位了还需要进位且最高位为9,就将整个数组往后移动一位,然后设置最高位为1.


Day5 Plus One



相关文章:

  • 2021-05-30
  • 2021-07-13
  • 2021-09-26
  • 2021-08-20
  • 2021-12-03
猜你喜欢
  • 2021-12-22
  • 2021-10-17
相关资源
相似解决方案