LeetCode练题——66. Plus one
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的更多相关文章
- 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 ...
- leetCode练题——12. Integer to Roman
1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
- leetCode练题——7. Reverse Integer
1.题目: 7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: I ...
- LeetCode练题——88. Merge Sorted Array
1.题目 88. Merge Sorted Array——Easy Given two sorted integer arrays nums1 and nums2, merge nums2 into ...
- LeetCode练题——70. Climbing Stairs
1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...
- LeetCode练题——67. Add Binary
1.题目 67. Add Binary——easy Given two binary strings, return their sum (also a binary string). The inp ...
- 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 ...
- LeetCode练题——53. Maximum Subarray
1.题目 53. Maximum Subarray——Easy Given an integer array nums, find the contiguous subarray (containin ...
- LeetCode练题——35. Search Insert Position
1.题目 35. Search Insert Position Easy 1781214Add to ListShare Given a sorted array and a target value ...
随机推荐
- Resharper快捷键使用
1: Alt+F7将你光标所在位置的变量的所有使用以列表的方式显示出来,显示结果的窗体可以像其他窗体那样停靠. 它的优点包括: 可以从所有使用中挑选只显示read usage或者write usa ...
- windows好用的cmd命令
1.如何查看本机ip局域网ip 在cmd中输入ipconfig 2.如何在不重启浏览器的情况下让刚修改的hosts生效, 因为服务器和浏览器都有DNS缓存,在cmd中执行ipconfig /flush ...
- SpringMVC框架应用
SSMSpringMVC框架 1. MVC设计模式:模型.视图.控制器: 视图:负责格式化数据并把他们呈现给用户,包括数据展示.用户交互.数据验证.界面设计等功能.对应组件:JSP或者HTML ...
- 题解【洛谷P1038/CJOJ1707】[NOIP2003提高组]神经网络
[NOIP2003]神经网络 Description 问题背景:人工神经网络( Artificial Neural Network )是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款 ...
- webpack4.41.0配置三(插件minCssExtract/ DefinePlugin/Html)
(注:如无特殊说明这里的配置文件都指的是webpack.config.js) minCssExtract 我们通常期望js和js文件一起,css和css文件一起.该插件将CSS提取到单独的文件中.它为 ...
- artTemplate使用说明
普通使用 <script id="test" type="text/html"> {{if isAdmin}} <h1>{{title} ...
- 剑指Offer:面试题20:表示数值的字符串
记录一下书上的写法.很整洁,每个函数的功能都显而易见.自己开始写的一堆if else语句像是一坨屎.另外注释的地方短路效应也要注意一下.总之这题还挺考察代码素质的(我这种就不存在什么素质..乱糟糟一团 ...
- sqli-libs(29(jspstudy)-31关)
Less_29 Less-29: 需要用到jspstudy跟phpstudy 搭建jspstudy: sqli-labs-master文件夹下面还有tomcat文件,这才是真正的关卡,里面的jsp ...
- 【PAT甲级】1110 Complete Binary Tree (25分)
题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点 ...
- java双亲委派模型
Java类加载器(ClassLoader) 双亲委派模式要求除了顶层的启动类加载器外,其余的类加载器都应当有自己的父类加载器,请注意双亲委派模式中的父子关系并非通常所说的类继承关系,而是采用组合关系来 ...