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 ...
随机推荐
- .Net Core初体验
对于C#语言支持(由C#1.0-C#7.1): 编码可以使用跨平台的IDE选择,就如同VS+Resharper一样方便: 运行效果:
- c数据结构 -- 线性表之 顺序存储结构 于 链式存储结构 (单链表)
线性表 定义:线性表是具有相同特性的数据元素的一个有限序列 类型: 1:顺序存储结构 定义:把逻辑上相邻的数据元素存储在物理上相邻的存储单元中的存储结构 算法: #include <stdio. ...
- CSS布局的四种定位方式
1.static(静态定位): 默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明).参考上篇随笔. 2.relative(相对 ...
- 路飞-celery框架
Celery 官方 Celery 官网:http://www.celeryproject.org/ Celery 官方文档英文版:http://docs.celeryproject.org/en/la ...
- linux软件下载
可以到linux官网下载:http://vault.centos.org/6.10/os/Source/SPackages/
- 【音乐欣赏】《Abnormalize》 - 凛として時雨
曲名:Abnormalize 作者:凛として時雨 [00:00.96]誰にも見せられないもの [00:06.44]頭の中溢れて [00:11.96]間違いさえも無い世界へ [00:17.16]迷い込ん ...
- python的setup和teardown
关于python unittest ① setup():每个测试函数运行前运行② teardown():每个测试函数运行完后执行③ setUpClass():必须使用@classmethod 装饰器, ...
- 2019-2020-2 20174314王方正 《网络对抗》 Exp0 Kali安装
本博旨记录安装Kali的具体步骤. 一.Vmware的安装 略. 二.Vmware的配置 选择[文件]-[新建虚拟机]. 出现新建虚拟机导向,按照以下图示配置每一步.
- AlertDialog 、SimpleDialog、 showModalBottomSheet、showToast 自定义 Dialog
// AlertDialog .SimpleDialog.showModalBottomSheet.showToast // 使用showToast安装插件 https://pub.dev/packa ...
- django-cors-headers
django-cors-headers介绍 一个Django应用程序,向响应头中添加跨域资源共享(CORS)头.这允许从其他来源向Django应用程序发出浏览器内请求,当然也可以自定义中间件然后添加响 ...