-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPlusOne_66.java
33 lines (28 loc) · 882 Bytes
/
PlusOne_66.java
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
package com.leetcode.problems.easy;
import com.geeksforgeeks.array.Rotate2DMatrix;
import com.util.LogUtil;
/**
* @author neeraj on 15/09/19
* Copyright (c) 2019, data-structures.
* All rights reserved.
*/
public class PlusOne_66 {
public static void main(String[] args) {
// LogUtil.printArray(plusOne(new int[]{1,2,3}));
// LogUtil.printArray(plusOne(new int[]{1,0,0,9}));
LogUtil.printArray(plusOne(new int[]{9,9,9}));
// LogUtil.printArray(plusOne(new int[]{9,0,1,9}));
}
public static int[] plusOne(int[] digits) {
for(int i=digits.length-1; i>=0; i--) {
if(digits[i] < 9) {
digits[i] = digits[i] + 1;
return digits;
}
digits[i] = 0;
}
int [] result = new int[digits.length + 1 ];
result[0] = 1;
return result;
}
}