zoukankan      html  css  js  c++  java
  • 13.leetcode66_plus_one

    
    

    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
  • 相关阅读:
    最短路--floyd算法模板
    poj2367 拓扑序
    poj1094 拓扑序
    hdu3231 拓扑序
    hdu1811 并查集+拓扑序
    hdu3342 拓扑序
    hdu2647 拓扑序
    hdu1285 拓扑序
    UVA10305 拓扑序
    $.proxy
  • 原文地址:https://www.cnblogs.com/19991201xiao/p/8424657.html
Copyright © 2011-2022 走看看