plus_one

 1# @leet start
 2class Solution:
 3    def plusOne(self, digits: list[int]) -> list[int]:
 4        """
 5        Given a number of digits, this returns the number + 1.
 6        To do this, we turn the list of digits into a number, and then add 1 to it.
 7        This can be done with `num = num * 10 + digit`.
 8
 9        Then we return this to the list by calling int on every string digit
10        in the string version of the int.
11        """
12        num = 0
13        for digit in digits:
14            num = num * 10 + digit
15
16        num += 1
17
18        return [int(n) for n in str(num)]
19
20
21# @leet end
22
23
24def test():
25    assert 2 + 2 == 4
class Solution:
 3class Solution:
 4    def plusOne(self, digits: list[int]) -> list[int]:
 5        """
 6        Given a number of digits, this returns the number + 1.
 7        To do this, we turn the list of digits into a number, and then add 1 to it.
 8        This can be done with `num = num * 10 + digit`.
 9
10        Then we return this to the list by calling int on every string digit
11        in the string version of the int.
12        """
13        num = 0
14        for digit in digits:
15            num = num * 10 + digit
16
17        num += 1
18
19        return [int(n) for n in str(num)]
def plusOne(self, digits: list[int]) -> list[int]:
 4    def plusOne(self, digits: list[int]) -> list[int]:
 5        """
 6        Given a number of digits, this returns the number + 1.
 7        To do this, we turn the list of digits into a number, and then add 1 to it.
 8        This can be done with `num = num * 10 + digit`.
 9
10        Then we return this to the list by calling int on every string digit
11        in the string version of the int.
12        """
13        num = 0
14        for digit in digits:
15            num = num * 10 + digit
16
17        num += 1
18
19        return [int(n) for n in str(num)]

Given a number of digits, this returns the number + 1. To do this, we turn the list of digits into a number, and then add 1 to it. This can be done with num = num * 10 + digit.

Then we return this to the list by calling int on every string digit in the string version of the int.

def test():
25def test():
26    assert 2 + 2 == 4