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. C++索引从0开始的堆排序算法实现

    更新2019年11月4日 04:26:35 睡不着觉起来寻思寻思干点啥吧,好像好久没写堆排了.于是写了个索引从0开始的堆排,这次把建堆函数略了并在heapsort主函数里,索引从0开始到size-1结 ...

  2. FineUIPro/Mvc/Core v6.1.0 发布了!

    FineUIPro/Mvc/Core v6.1.0 正式发布了(2019-12-25),这个版本主要是BUG修正,并增加了一些新特性,建议升级到此版本. 在列举新版本特性之前,我们先来回顾下每次发布大 ...

  3. jvm(1):内存结构

    JVM内存结构 JVM内存的运行时数据区: 线程私有(在线程启动时创建) 程序计数器Program Counter Register 一块较小的内存空间,可以看作是当前线程所执行的字节码的行号指示器, ...

  4. SaltStack常用的模块

    目录 1. SaltStack模块介绍 2. SaltStack常用模块 2.1 SaltStack常用模块之network 2.1.1 network.active_tcp 2.1.2 networ ...

  5. AcWing 338. 计数问题

    #include <iostream> #include <algorithm> #include <vector> using namespace std; ; ...

  6. MyBatis(3)——配置解析

    MyBatis中文参考指南:MyBatis用户指南 //------------核心配置文件说明------------// //*在注释中进行说明 <configuration> < ...

  7. Maven安装与学习

    一.安装 1.下载http://maven.apache.org/download.cgi 2.选择zip格式 安装完后解压到某一位置(E:\xitong\major\apache-maven-3.6 ...

  8. drf解析模块,异常模块,响应模块,序列化模块

    复习 """ 1.接口:url+请求参数+响应参数 Postman发送接口请求的工具 method: GET url: https://api.map.baidu.com ...

  9. Logarithmic-Trigonometric积分系列(二)

    \[\Large\displaystyle \int_0^{\pi/2}\ln^2(\sin x)\ln(\cos x)\tan x \,{\rm d}x\] \(\Large\mathbf{Solu ...

  10. APP项目下载及运行

    1.首先下载Git 2.再下载安装node.js 3.dos窗口下载node.js依赖jar包 执行命令:npm install 4.从Git上down项目 5.运行项目 在项目根目录下 右键 打开 ...