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】的更多相关文章

  1. leetcode刷题-66加一

    题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...

  2. 【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 ' ' ...

  3. leetcode 加一

    给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...

  4. Leetcode加一 (java、python3)

    加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. Given ...

  5. LeetCode Array Easy 66. Plus One

    Description Given a non-empty array of digits representing a non-negative integer, plus one to the i ...

  6. LeetCode练题——66. Plus one

    1.题目 66. Plus One——easy Given a non-empty array of digits representing a non-negative integer, plus ...

  7. 【leetcode❤python】66. Plus One

    class Solution:      # @param digits, a list of integer digits      # @return a list of integer digi ...

  8. LeetCode题型分类及索引

    目录 这是一个对LeetCode题目归类的索引,分类标准参考了July大神的<编程之法>以及LeetCode的tag项.分类可能还不太合理,逐步完善,请见谅~ 题主本人也在一点一点的刷题, ...

  9. Leecode刷题之旅-C语言/python-66加一

    /* * @lc app=leetcode.cn id=66 lang=c * * [66] 加一 * * https://leetcode-cn.com/problems/plus-one/desc ...

  10. Project Euler18题 从上往下邻接和

    题目:By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ...

随机推荐

  1. 微信小程序 之 请求函数封装

    封装的request的代码 /** * @desc API请求接口类封装 */ /** * POST请求API * @param {String} url 接口地址 * @param {Object} ...

  2. 【Excle数据透视表】如何在Excle中使用数据鼠标拖放

    数据透视表建立好之后,我们有时候需要改动数据透视表,那么直接可以对字段进行拖拽就可以改变,这样使数据透视变得比较方便使用 原始样式 拖拽后样式 步骤 右键数据透视表任意单元格→数据透视表选项→显示→经 ...

  3. chrome浏览器提取网页视频

    http://blog.csdn.net/pipisorry/article/details/37728839 在我们平时上网看视频听音乐时都会产生缓存,可是我们非常难通过一些软件把当中的视频和音乐文 ...

  4. Linux作业(三)-shell统计某文章中出现频率最高的N个单词并排序输出出现次数

    Linux课上的作业周三交,若有考虑不周到的地方,还请多多不吝赐教. shell处理文本相关的经常使用命令见此博客 # #假设输入两个參数 则第一个为统计单词的个数.第二个为要统计的文章 #假设输入一 ...

  5. iOS应用程序开发之内购

    内购简介 配置iTunes Connect iOS客户端开发工作 一.内购简介 1⃣️通过苹果应用程序商店有三种主要赚钱的方式: –直接收费(与国内大部分用户的消费习惯相悖,如果直接收费,不要设置为6 ...

  6. 修改pip源为国内网站

    import os,sys,platformini="""[global]index-url = https://pypi.doubanio.com/simple/[in ...

  7. Mysql-Proxy实现mysql读写分离、负载均衡 (转)

    在mysql中实现读写分离.负载均衡,用Mysql-Proxy是很容易的事,不过大型处理对于性能方面还有待提高,主要配置步骤如下: 1.1. mysql-proxy安装 MySQL Proxy就是这么 ...

  8. spring利用ApplicationListener自启动

    近期在用mina获取server的数据,但没有和spring进行集成,就利用ApplicationListener实现了自启动 package com.gamesvr.minaenpo; import ...

  9. 【COCOS2DX-LUA 脚本开发之一】在Cocos2dX游戏中使用Lua脚本进行游戏开发(基础篇)并介绍脚本在游戏中详细用途!

    [COCOS2DX-LUA 脚本开发之一]在Cocos2dX游戏中使用Lua脚本进行游戏开发(基础篇)并介绍脚本在游戏中详细用途! 分类: [Cocos2dx Lua 脚本开发 ] 2012-04-1 ...

  10. 当客户端提交更新数据请求时,是先写入edits,然后再写入内存的

    http://blog.sina.com.cn/s/blog_6f83c7470101b7d3.html http://blog.csdn.net/slq1023/article/details/49 ...