algorithm notes: leetcode#66 plus one

Problem


Analysis


Solution


1
2
3
4
5
6
7
class (object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
return [int(s) for s in str(int(''.join([str(d) for d in digits]))+1)]
1
2
3
4
5
6
7
8
9
10
class (object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
num = 0
for d in digits:
num = num * 10 + d
return [int(d) for d in str(num+1)]

66. Plus One