-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlusOne66.java
More file actions
35 lines (30 loc) · 799 Bytes
/
PlusOne66.java
File metadata and controls
35 lines (30 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.leetcode.problems;
class Solution66 {
public int[] plusOne(int[] digits) {
digits[digits.length-1] += 1;
for (int i = digits.length-1; i >= 1 ; i--) {
if(digits[i]>9)
{
digits[i]%=10;
digits[i-1]+=1;
}
}
int[] res = new int[digits.length+1];
if(digits[0] > 9)
{
for (int i = 1; i < digits.length; i++) {
res[i+1] = digits[i];
}
res[1] = digits[0]%10;
res[0] = 1;
return res;
}
return digits;
}
}
public class PlusOne66 {
public static void main(String[] args) {
Solution66 s = new Solution66();
int[] ints = s.plusOne(new int[]{9,9,9});
}
}