class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
stack = []
carry = 1
for i in range(len(digits)-1, -1, -1):
new = digits[i] + carry
carry = new // 10
stack.append(new % 10)
if carry: # carry == 1
stack.append(carry)
return stack[::-1]'LeetCode > Top Interview 150' 카테고리의 다른 글
| 35. Search Insert Position (0) | 2024.12.20 |
|---|---|
| 172. Factorial Trailing Zeroes (2) | 2024.12.18 |
| 201. Bitwise AND of Numbers Range (0) | 2024.12.18 |
| 137. Single Number II (0) | 2024.12.18 |
| 67. Add Binary (0) | 2024.12.17 |