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 ...
随机推荐
- MySQL中int(11)的意思
参考文献:https://segmentfault.com/a/1190000012479448 int(11)中的11代表的是字符的显示宽度,在字段类型为int时,无论你显示宽度设置为多少,int类 ...
- Java:面向对象的编程语言
java是面向对象的编程语言 Object,就是指面向对象的对象,对象就是实例. 在java里,对象是类的一个具体实例.就像:人,指一个类.你.我.他.张三.李四.王五等则是一个个具体的实例,也就是j ...
- sublime添加自己的编译环境_添加一个.app或者.exe文件执行脚本
如何添加一个.app或者.exe文件执行脚本 看了很多简书和博客,还是搞不好,最后参考官方文档搞定了: http://www.sublimetext.com/docs/3/build_systems. ...
- YAML(YML)语法详解
ansible playbook是由yaml(yml)语法书写,结构清晰,可读性强,所以必须掌握yaml(yml)基础语法 语法 描述 锁进 YAML使用固定的缩进风格表示层级结构,每个缩进由两个空 ...
- java基础(六)之继承初探
什么是继承? 一个类得到了另一个类当中的成员变量和成员方法.java只支持单继承.一个子类只允许继承一个父类,一个父类可以被多个子类继承. 比如下面的一个例子, 先创建一个Person类 class ...
- org.apache.httpcomponents.httpclient
apache org doc :http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e49 ...
- sublime 最常用的快捷键.gif
Ctrl+D 把光标放在文本上,按下⌘+ D将选择这个文本.多次按下⌘+ D则会增加匹配项 Alt+F3 会选中光标所在文本的所有匹配项 Ctrl+Shift+' 这是一个法宝,也许你希望所有的属性保 ...
- 【网易官方】极客战记(codecombat)攻略-地牢-轰轰
关卡连接: https://codecombat.163.com/play/level/pong-pong 挑战:使用迄今为止学到的所有编程技巧编写最短的解决方案! 简介: 单挑,这是特殊的挑战关卡! ...
- python正则匹配次数,贪婪和非贪婪
贪婪模式 {m,n}表示匹配子串的次数>=m and <=n,再此分为内匹配次数尽可能的多 贪婪模式 {,n}表示 >=0 and <=n 贪婪模式 {m,} 表示> ...
- static的使用总结
全局静态变量 全局变量前加上关键字static,全局变量就定义成一个全局静态变量.,全局静态变量存储在静态存储区,在整个程序运行期间一直存在.全局静态变量在程序运行之前就存在. 初始化:未经初始化的全 ...