LeetCode & Q66-Plus One-Easy
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的更多相关文章
- [LeetCode] 036. Valid Sudoku (Easy) (C++)
指数:[LeetCode] Leetcode 解决问题的指数 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 036. ...
- [array] leetcode - 53. Maximum Subarray - Easy
leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...
- C#解leetcode 228. Summary Ranges Easy
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- leetcode 283. Move Zeroes -easy
题目链接:https://leetcode.com/problems/move-zeroes/ 题目内容: Given an array nums, write a function to move ...
- 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 ...
- leetcode 198. House Robber (Easy)
https://leetcode.com/problems/house-robber/ 题意: 一维数组,相加不相邻的数组,返回最大的结果. 思路: 一开始思路就是DP,用一维数组保存dp[i]保存如 ...
- 【leetcode】 Unique Path ||(easy)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【leetcode】triangle(easy)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- 【leetcode】Implement strStr() (easy)
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【leetcode】Plus One (easy)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
随机推荐
- Delphi的RzDbgrid改变某行的背景色
本想改变符合条件的行的背景色,试了DbgridEh和原生的Dbgrid直接在DrawColumnCell事件中写重绘代码就好了,But在RzDbgrid就不起效果,查了好一会,百度了一大堆,都是千篇一 ...
- Listener监听器生命周期
一.Listener生命周期 listener是web三大组件之一,是servlet监听器,用来监听请求,监听服务端的操作. listener分为:(都是接口类,必须实现相应方法) 1.生命周期监听器 ...
- JS中的闭包问题
一.闭包:在函数外也可使用局部变量的特殊语法现象 全局变量 VS 局部变量: 全局变量:优点:可共享,可重用; 缺点:在任意位置都可随意修改——全局污染 局部变量:优点:安全 缺点:不可共享,不可重用 ...
- http进阶
前言: 上一篇博文已经说到了,apache2.4简单的配置,端口,持久连接,MPM,DSO,路径下基于来源控制,页面特性,日志设置 安全域,虚拟主机等等. 一:URL URL是互联中获取标记资源的方式 ...
- Filecoin挖矿进展
预计Filecoin第一个版本发布最早在 2018.3月份(预计) Protocol Labs这次ICO拿到了2.05亿美元,已经富得流油了,相信开发进度会快很多,Filecoin论文发表最早 ...
- equals和hashCode详解
equals和hashCode详解 http://www.cnblogs.com/Qian123/p/5703507.html
- Could not create the view: An unexpected exception was thrown的解决方法
MyEclipse下面的server窗口突然不能正常显示了,而且还显示Could not create the view: An unexpected exception was thrown(无法创 ...
- MyBatis动态SQL小结
6:用于实现动态sql的元素及其用法 if+set--完成更新操作 if+where --完成多条件查询 if+完成多条件查询(替代where)或完成更新操作(替代set) choose(when,o ...
- vue+webpack+element-ui+git
webpack.config.jsconst { resolve } = require('path') const webpack = require('webpack') const HtmlWe ...
- 基于hi-nginx的web开发(python篇)——使用jinja2模板引擎
模板引擎的使用在web开发中是不可避免和必要的.hi.py框架使用jinja2作为模板引擎. 为了使用hi.py提供的jinja2引擎,首先需要引入它: from hi import hi,templ ...