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.

思路:digits[i] +1 有两种结果:(1)digits[i] < 9: 不进位 (2)digits[i] = 9: digits[i] = 0;

class Solution {
public int[] plusOne(int[] digits) { for (int i = digits.length - 1; i >=0 ; i--){
if (digits[i] < 9) {
digits[i] ++;
return digits;
}
digits[i] = 0;
} int[] newNumber = new int[digits.length + 1];
newNumber[0] = 1;
return newNumber;
}
}

Leetcode66-Plus One-Eassy的更多相关文章

  1. leetcode-66.加一

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

  2. LeetCode----66. Plus One(Java)

    package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...

  3. [LeetCode66]Plus One

    题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...

  4. [Swift]LeetCode66. 加一 | Plus One

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

  5. leetCode66:加一

    /** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { if(digits[di ...

  6. 【leetcode-66】 加一

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

  7. leetcode66

    public class Solution { public int[] PlusOne(int[] digits) { ]; < ) { digits[digits.Length - ]++; ...

  8. Install and run DB Query Analyzer 6.04 on Microsoft Windows 10

          Install and run DB Query Analyzer 6.04 on Microsoft Windows 10  DB Query Analyzer is presented ...

  9. DB Query Analyzer 6.04 is distributed, 78 articles concerned have been published

        DB Query Analyzer 6.04 is distributed,78 articles concerned have been published  DB Query Analyz ...

  10. How to create DB2 user function easily by DB Query Analyzer 6.03

    How to create DB2user function easily by DB Query Analyzer 6.03 Ma Genfeng (Guangdong Unitoll Servic ...

随机推荐

  1. Jmeter自己jar包的引用

    1.编写清空指定文件夹里所有内容的jar包 package org.na;import java.io.File;public class deletedir {    public static b ...

  2. python 内置函数format

    Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % . format 函数可以接受不限个参数 ...

  3. Log4j基础知识

    Log4J是Apache的一个开放源代码的项目.通过使用Log4J,程序员可以控制日志信息输送的目的地,包括控制台,文件,GUI组件和NT事件记录器,也可以控制每一条日志的输出格式,或通过定义每一条日 ...

  4. Vector集合——单列集合的“祖宗”类

    是实现可增长的对象数组:所以底层也是数组: 与collection集合不同的是,vector是同步的,意味着是单线程的,意味着效率低,速度慢, 所以在jdk1.2版本之后被ArrayList集合所取代 ...

  5. MySQL存储引擎MyISAM与InnoDB区别总结整理

    在MySQL的 可重复读隔离级别 中,是解决了幻读的读问题的. 1. MySQL默认存储引擎的变迁 在MySQL 5.5之前的版本中,默认的搜索引擎是MyISAM,从MySQL 5.5之后的版本中,默 ...

  6. Fabric架构:抽象的逻辑架构与实际的运行时架构

    Fabric从1.X开始,在扩展性及安全性上面有了大大的提升,且新增了诸多的新特性: 多通道:支持多通道,提高隔离安全性. 可拔插的组件:支持共识组件.权限管理组件等可拔插功能. 账本数据可被存储为多 ...

  7. golang学习笔记7 使用beego swagger 实现API自动化文档

    golang学习笔记7 使用beego swagger 实现API自动化文档 API 自动化文档 - beego: 简约 & 强大并存的 Go 应用框架https://beego.me/doc ...

  8. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

    elasticsearch安装时遇到的错误 问题翻译过来就是:elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536: 解决办法: #切换到root用户修改 vim /etc ...

  9. Codeforce 814A - An abandoned sentiment from past (贪心)

    A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since ...

  10. Kali linux vim使用命令笔记

    Kali Linux系统的vi编辑器/vim编辑器的使用和CentOS有很多不同.基本使用方法如下 1.vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mode).插入模式 ...