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 ...
随机推荐
- 为什么JVM指定-Xmx参数后占用内存会变少?
嘿,你能顺便过来看看这个奇怪的事情吗?” 就是让我提供支持的这个事情,驱使我写下这篇博客的.这个特殊的问题是,不同工具给出的可用内存的报告是不一样的. 简而言之,工程师正在调查特定应用程序的内存使用. ...
- Git提交时提示‘The file will have its original line endings in your working directory’
Git提交时提示'The file will have its original line endings in your working directory' Git出现错误 git add -A ...
- STL学习笔记(string)
动机 C++标准程序库中的string class使我们可以将string当做一个一般型别.我们可以像对待基本型别那样地复制.赋值和比较string, 再也不必但系内存是否足够.占用的内存实际长度等问 ...
- expect获取返回值
对于获取多台server状态且不用交互须要用到expect,但有时候expect无法获取返回值.这里解释一下expect怎样获取返回值 expect -c " spawn $1; ...
- linux路由服务
本文介绍怎样使用linux创建一台简单的路由server. 主要包含几个參数的设置:ip_forward和rp_filter. 1.开启IP forwarding # 重新启动后失效 $ echo & ...
- TRIZ系列-创新原理-23-反馈原理
反馈原理的详细表述例如以下:1)引入反馈:2)假设已经有反馈,那么改变它这个原理告诉我们应当从系统中尽量多收集反馈信息.并用这些信息来矫正系统的作用.非常easy看出,引入反馈是系统自己主动控制 ...
- [译]GLUT教程 - 整合代码5
Lighthouse3d.com >> GLUT Tutorial >> Extras >> The Code So Far V 该代码与位图字体的代码类似.区别是 ...
- 使用Application Loader上传APP流程解读[APP公布]
本文仅仅是提供一个公布流程的总体思路.假设没有公布经验.建议阅读苹果官方公布文档或者Google搜索具体教程. 1.申请开发人员账号:99美金的(须要信用卡支付),详细流程网上有非常多样例.自行搜索. ...
- ubuntu 16.04安装visual studio code 提示libnss3版本低:NSS >= 3.26 is required
Linux Ubuntu 1604安装VS CODE之后,执行./code报错误: [3781:0914/160851.489979:FATAL:nss_util.cc(632)] NSS_Versi ...
- cxf 创建动态webService
D:\developTools\apache-cxf-2.5.2\samples\wsdl_first_dynamic_client CXF 方法 cxf方法 serviceInfo.getBindi ...