LeetCode:加一【66】
LeetCode:加一【66】
题目描述
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
最高位数字存放在数组的首位, 数组中每个元素只存储一个数字。
你可以假设除了整数 0 之外,这个整数不会以零开头。
示例 1:
输入: [1,2,3]
输出: [1,2,4]
解释: 输入数组表示数字 123。
示例 2:
输入: [4,3,2,1]
输出: [4,3,2,2]
解释: 输入数组表示数字 4321。
题目分析
Java题解
class Solution {
public int[] plusOne(int[] digits) {
int n = digits.length;
for(int i=n-1;i>=0;i--)
{
if(digits[i]<9){
digits[i]++;
return digits;
}
digits[i]=0;
}
int[] newNums = new int[n+1];
newNums[0]=1;
return newNums;
}
}
LeetCode:加一【66】的更多相关文章
- leetcode刷题-66加一
题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...
- 【LeetCode算法-58/66】Length of Last Word/Plus One
LeetCode第58题: Given a string s consists of upper/lower-case alphabets and empty space characters ' ' ...
- leetcode 加一
给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...
- Leetcode加一 (java、python3)
加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. Given ...
- LeetCode Array Easy 66. Plus One
Description Given a non-empty array of digits representing a non-negative integer, plus one to the i ...
- LeetCode练题——66. Plus one
1.题目 66. Plus One——easy Given a non-empty array of digits representing a non-negative integer, plus ...
- 【leetcode❤python】66. Plus One
class Solution: # @param digits, a list of integer digits # @return a list of integer digi ...
- LeetCode题型分类及索引
目录 这是一个对LeetCode题目归类的索引,分类标准参考了July大神的<编程之法>以及LeetCode的tag项.分类可能还不太合理,逐步完善,请见谅~ 题主本人也在一点一点的刷题, ...
- Leecode刷题之旅-C语言/python-66加一
/* * @lc app=leetcode.cn id=66 lang=c * * [66] 加一 * * https://leetcode-cn.com/problems/plus-one/desc ...
- Project Euler18题 从上往下邻接和
题目:By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ...
随机推荐
- 02-1设置第一启动项--电脑怎么进入BIOS的方法集合
电脑怎么进入BIOS的方法集合 很多时候为了对电脑进行相关设置,我们必须进入电脑的bios界面,但是不同的电脑进入bios的方法各不相同,小编今天就在这儿将各种电脑进入bios的方法汇总一下,希望对你 ...
- Android 开发 Eclipse使用SVN
1 help--->install new software--->add 2 name自定义 location填入内容见3 3 http://subclipse.tigris.org/s ...
- Eclipse更改默认工作环境编码为UTF-8(9.6)
1 window---->preference------>General----->Workspace---->Text file encoding---->Other ...
- Delphi中array of const应用
Delphi的Format函数大家都用得很多,第二个参数用着确实很方便.最近在数据库开发应用中需要自己创建一个带array of const参数的函数,对于常用的类型String,Integer,Po ...
- CSS 选择器 :last-child与:last-of-type的区别
:last-child----represents the last element among a group of sibling elements. CSS伪类 :last-child 代表在一 ...
- mac权限
mac文件后面出现@权限 去除方法: xattr -c 文件名 目录也可以
- nginx 根据参数选择文档根目录
server { listen 80; server_name testmanage.h5.91wan.com; index index.html index.htm ...
- 篇一、安装配置Android Studio
系统:Mac 10.10 Java JDK:官方JDK1.8 IDE:Android Studio 1.2 Android SDK:24.2 模拟器:genymtion 安装 Mac版本的Androi ...
- Sphinx(Coreseek)安装和使用指南
1.安装 1.1安装mmseg ./bootstrap # 必须执行,不然安装会失败 ./configure --prefix=/usr/local/mmseg- #指定安装目录 make make ...
- python 3 关于requests库的 text / content /json
最近在爬SDFDA的数据,刚开始用urllib.request 库,一直连不到数据 : 后来通过CHROME浏览器的F12,发现该 网站用的是JSON格式{}'Content-Type': 'appl ...