1、题目

66. Plus One——easy

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

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

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

Example 1:

Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:

Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.

2、我的解法

 # -*- coding: utf-8 -*-
# @Time : 2020/2/8 17:04
# @Author : SmartCat0929
# @Email : 1027699719@qq.com
# @Link : https://github.com/SmartCat0929
# @Site :
# @File : 66.PLus one.py from typing import List
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
res = 0
for count, i in enumerate(reversed(digits)): # 第一步,把列表转化成整数
res += i * (10 ** count)
result=res+1 # 第二步,对生成的整数进行 +1 运算
b = [int(x) for x in str(result)] # 第三步,转化成列表—————采用列表生成式的方法
return b
print(Solution().plusOne([1,2,2,9]))

LeetCode练题——66. Plus one的更多相关文章

  1. leetCode练题——38. Count and Say

    1.题目 38. Count and Say The count-and-say sequence is the sequence of integers with the first five te ...

  2. leetCode练题——12. Integer to Roman

    1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

  3. leetCode练题——7. Reverse Integer

    1.题目:   7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: I ...

  4. LeetCode练题——88. Merge Sorted Array

    1.题目 88. Merge Sorted Array——Easy Given two sorted integer arrays nums1 and nums2, merge nums2 into  ...

  5. LeetCode练题——70. Climbing Stairs

    1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...

  6. LeetCode练题——67. Add Binary

    1.题目 67. Add Binary——easy Given two binary strings, return their sum (also a binary string). The inp ...

  7. LeetCode练题——58. Length of Last Word

    1.题目 58. Length of Last Word——Easy Given a string s consists of upper/lower-case alphabets and empty ...

  8. LeetCode练题——53. Maximum Subarray

    1.题目 53. Maximum Subarray——Easy Given an integer array nums, find the contiguous subarray (containin ...

  9. LeetCode练题——35. Search Insert Position

    1.题目 35. Search Insert Position Easy 1781214Add to ListShare Given a sorted array and a target value ...

随机推荐

  1. springboot13(redis缓存)

    redis做springboot2.x的缓存 1.首先是引入依赖 <dependency> <groupId>org.springframework.boot</grou ...

  2. Vue(二)

    ---恢复内容开始--- 1.vue条件指令 可以运行加减运算 可以进行if判断 <!DOCTYPE html> <html> <head> <meta ch ...

  3. Ninject 2.x细说---1.基本使用

    Ninject 2.x细说---1.基本使用 https://blog.csdn.net/weixin_33809981/article/details/86091159   本来想使用一下Ninje ...

  4. js获取当前时间:yyyy-MM-dd HH:MM:SS

    var nowDate = new Date();var year = nowDate.getFullYear(); < ? ; ? " + nowDate.getDate() : n ...

  5. NOIP做题练习(day2)

    A - Reign 题面 题解 最大子段和+\(DP\). 预处理两个数组: \(p[i]\)表示 \(i\) 之前的最大子段和. \(l[i]\)表示 \(i\) 之后的最大子段和. 最后直接输出即 ...

  6. ansible笔记(5):常用模块之命令类模块

    1.command模块 它的作用是帮助我们在远程主机上执行命令. [注意]使用command模块在远程主机中执行命令时,不会经过远程主机的shell处理,在使用command模块时,如果需要执行的命令 ...

  7. ansible笔记(1):ansible基本概念

    一.基础概念 1.ansible是什么? ansible是一个配置管理工具,是一个自动化运维工具. 2.ansible能做什么? 它可以完成一组批量化的工作任务,或者经常重复性的工作任务.例如:a.在 ...

  8. 使用VS2017开发安卓app(1)环境搭建

    本人新手,边学习边写笔记,有错误不足之处,望各位博友指正~ 想要用vs开发安卓app,需要在安装时勾选 Xamarin是一个跨平台开发框架.在这一框架内,开发iOS.Android.Windows P ...

  9. 洛谷 P4555 [国家集训队]最长双回文串(Manacher)

    题目链接:https://www.luogu.com.cn/problem/P4555 首先明白两个回文串,那么要使两个回文串成立,那么我们只能把$'#'$作为中间节点. 然后我们跑一边Manache ...

  10. itest(爱测试) 4.3.1 发布,开源BUG 跟踪管理 & 敏捷测试管理软件

    4.3.0 发布后有三个用户强烈要求的更新,所以一周后4.3.1出炉,有点版本帝的味道哈,用户的反馈是我们持续升级的动力...... itest 简介:查看简介 test 开源敏捷测试管理,testO ...