Array

Description:

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

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.

不得不承认,我已经蠢出天际了,题目愣是没看懂,试了好几遍才看出来要干嘛(明明看得懂英文的...哎...)

这题开始有些情况没考虑到,wrong了两次....

my Solution:

public 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;
} else {
digits[i] = 0;
}
}
int[] array = new int[n + 1];
array[0] = 1;
return array;
}
}

LeetCode & Q66-Plus One-Easy的更多相关文章

  1. [LeetCode] 036. Valid Sudoku (Easy) (C++)

    指数:[LeetCode] Leetcode 解决问题的指数 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 036. ...

  2. [array] leetcode - 53. Maximum Subarray - Easy

    leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...

  3. C#解leetcode 228. Summary Ranges Easy

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  4. leetcode 283. Move Zeroes -easy

    题目链接:https://leetcode.com/problems/move-zeroes/ 题目内容: Given an array nums, write a function to move ...

  5. LeetCode: 520 Detect Capital(easy)

    题目: Given a word, you need to judge whether the usage of capitals in it is right or not. We define t ...

  6. leetcode 198. House Robber (Easy)

    https://leetcode.com/problems/house-robber/ 题意: 一维数组,相加不相邻的数组,返回最大的结果. 思路: 一开始思路就是DP,用一维数组保存dp[i]保存如 ...

  7. 【leetcode】 Unique Path ||(easy)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. 【leetcode】triangle(easy)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  9. 【leetcode】Implement strStr() (easy)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  10. 【leetcode】Plus One (easy)

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

随机推荐

  1. IT连创业系列:新的一年,先淫文一篇!

    办公室窗外,有鸟声〜〜 在IT连创业走过的日子里,这是我第一次听见鸟声. 也许,是曾经的忙碌,封锁了自己的心眼. 岁月秒秒: 当初燃烧的火焰,从红,烧成了蓝. 曾经的内心湃澎,化成了平淡坚持. 但这, ...

  2. 学习ASP.NET Core Razor 编程系列一

    一. 概述 .NET Core 1.0发布的时候就想进行学习的,不过根据微软的以往的发布规律1.0版可以认为是大众测试版,2.0才算稳定.现在2.1都已经发布了预览版,之前对其"不稳定&qu ...

  3. MongoDB 搭建文件存储的方案

    用云的话,节省你开发成本,快速上线,数据比较安全.缺点是一旦用了他们的,形成习惯以后,数据想迁移就会比较麻烦,你会越来越依赖,而且规模上去以后价格并不低.早年自己做的话,你需要实现分布式文件系统,这个 ...

  4. java--抽象类实例(包含静态内部抽象类)

    静态内部抽象类可以被继承. public class testfather { public static void main(String[] args) { person.talk2 a = ne ...

  5. 毫秒级检测!你见过带GPU的树莓派吗?

    树莓派3B+英特尔神经计算棒进行高速目标检测 转载请注明作者梦里茶 代码: 训练数据预处理: https://gist.github.com/ahangchen/ae1b7562c1f93fdad1d ...

  6. openflow 和 sdn (软件定义网络) 原理和教程

    OpenFlow概述 OpenFlow简介 通俗的讲,OpenFlow是使用类似于API进程配置网络交换机的协议.OpenFlow的思路很简单,网络设备维护一个FlowTable并且只按照FlowTa ...

  7. 浅析JavaScript的prototype

    一.JavaScript对象的创建 (1)对象方法 function Student(name){ this.name=name; this.showName=function(){ alert(&q ...

  8. TortoiseGit- 创建本地新分支,提交推送到远程,本地新分支合并到工作分支,提交到远程工作分支等。

    整体思路: 创建本地新分支 (create branch)  -- 切换到本地新分支工作 (switch/checkout) --提交修改 (commit)  -- 推送到远程新分支 (push)  ...

  9. Acer Aspire E1 471G 加装SSD+机械盘后无法启动的问题

    老笔记本 Acer Aspire E1 471G 加装了一块 SSD 作为系统盘(win10),原机械盘格式化后,装在光驱托架上作为数据盘. 可能会出现: 系统无法启动,显示找不到启动设备,并且在F2 ...

  10. 【Python】 零碎知识积累 II

    [Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...