-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path66.加一.py
65 lines (63 loc) · 1.09 KB
/
66.加一.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
# @lc app=leetcode.cn id=66 lang=python3
#
# [66] 加一
#
# https://leetcode.cn/problems/plus-one/description/
#
# algorithms
# Easy (45.90%)
# Likes: 1016
# Dislikes: 0
# Total Accepted: 488K
# Total Submissions: 1.1M
# Testcase Example: '[1,2,3]'
#
# 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一。
#
# 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。
#
# 你可以假设除了整数 0 之外,这个整数不会以零开头。
#
#
#
# 示例 1:
#
#
# 输入:digits = [1,2,3]
# 输出:[1,2,4]
# 解释:输入数组表示数字 123。
#
#
# 示例 2:
#
#
# 输入:digits = [4,3,2,1]
# 输出:[4,3,2,2]
# 解释:输入数组表示数字 4321。
#
#
# 示例 3:
#
#
# 输入:digits = [0]
# 输出:[1]
#
#
#
#
# 提示:
#
#
# 1
# 0
#
#
#
# @lc code=start
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
num = "".join([str(i) for i in digits])
num = int(num) + 1
return [int(i) for i in str(num)]
# @lc code=end