首页 > 其他 > 详细

13.leetcode66_plus_one

时间:2018-02-07 00:10:17      阅读:293      评论:0      收藏:0      [点我收藏+]

1.题目描述

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.

 给定一个非负整数,表示为一个非空的数字数组,再加上一个整数。

2.题目分析

列表转字符串,字符串转数字,加上整数后转回即可

3.解题思路

class Solution(object):
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        num=‘‘        #定义空字符串
        for i in digits: #列表转字符串(用join函数也可以)
            num+=(str(i))
        digits=int(num) #字符串转数字
        digits+=1       #数字加一
        digits=str(digits) #转字符串
        nums=[]  
        for i in digits:  #转列表
            nums.append(int(i))
        return nums

 

 

13.leetcode66_plus_one

原文:https://www.cnblogs.com/19991201xiao/p/8424657.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!