-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path66.plus-one.java
More file actions
32 lines (30 loc) · 770 Bytes
/
Copy path66.plus-one.java
File metadata and controls
32 lines (30 loc) · 770 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
/*
* @lc app=leetcode id=66 lang=java
*
* [66] Plus One
*/
// @lc code=start
class Solution {
public int[] plusOne(int[] digits) {
int carry = 1;
int[] edgecase = new int[digits.length + 1];
for(int i = digits.length - 1; i >= 0; i--) {
digits[i] += carry;
if(digits[i] == 10) {
digits[i] = 0;
if(i == 0) {
edgecase[0] = 1;
for(int j = 0; j < digits.length; j++) {
edgecase[j+1] = digits[j];
}
return edgecase;
}
carry = 1;
continue;
}
carry = 0;
}
return digits;
}
}
// @lc code=end