程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python leetcode66: plus one

編輯:Python

subject :

 The highest digit is placed at the top of the array , Each element in the array stores only a single number .
You can assume that except for integers 0 outside , This integer will not start with zero .
[9,9] ===> [1,0,0]
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
sum = 0
l = len(digits)-1
for s in digits:
sum += s * 10**l
l = l -1
sum += 1
result = list(str(sum)) # If so str(sum) You can get the same result , But the efficiency is relatively low
result = list(map(int,result)) # use Python take list Medium string Convert to int, among result Itself should be list type , Here, you may default to string Type into list type
return result
digits = [9,9]
S = Solution()
result = S.plusOne(digits)
print(result)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved