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 ...
随机推荐
- Zabbix 监控 Docker容器
我们可以通过Python提供的模块docker来取各个docker容器的监控参数.参考文档:http://docker-py.readthedocs.io/en/stable/containers.h ...
- javaScript数组操作整理
一.js数组 1.创建数组: var arr = new Array();//创建没有元素空数组 var arr1 = new Array("value1","valeu ...
- Android JNI开发之C/C++层调用JAVA
一.从C/C++层调用JAVA层代码(无参数调用) //在c代码里面调用java代码里面的方法 // java 反射 // 1 . 找到java代码的 class文件 // jclass (*Find ...
- Java 多线程之哪个对象才是锁?
问题背景 在感觉正常的使用ArrayList的迭代删除的操作的时候,发现了如下的崩溃日志: Caused by: java.util.ConcurrentModificationException a ...
- TypeScript入门知识四(表达式和循环)
一,箭头表达式 用来声明匿名函数,消除传统匿名函数的this指针问题 //单行的话可以省略{},多行的不能省. var sum = (arg1,arg2)=> arg1+arg2; //定义一个 ...
- C语言引用另一个源文件中定义的数组
C语言中是可以引用另外一个源文件的全局数组的,但是不能引用局部数组. 引用方式举例如下: 设a.c文件有有数据定义 int array1[10]; 现有b.c文件中想访问a.c中的array1数组 ...
- 对JS prototype的理解
1.什么是prototype? function F() {} f1 = new F();f2 = new F(); 以上的代码,F()是一个构造函数,f1和f2是由这个构造函数产生的对象. prot ...
- 【Unity3D与23种设计模式】单例模式(Singleton)
GoF中定义: "确认类只有一个对象,并提供一个全局的方法来获取这个对象" 使用单例模式的前提 它只能产生一个对象且不能够被继承 单例模式的优点: 提供方便获取唯一对象的方法 可以 ...
- JSON基础(Java)
1.json maven 依赖(以下都以第一个包为例) <dependency> <groupId>org.json</groupId> <artifactI ...
- Java设计模式-责任链模式
提出问题: 最初接触责任链模式就是在struts2中,在当时学的时候看了一眼,大概知道了原理,最近在复习,模拟struts2,说是模拟只是大体模拟了struts2的工作流程,很多东西都是写死的,只是为 ...