Submission Detail

111 / 111 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 41.1 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
75
80
85
90
95
100
105
110
java
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
80
90
100
110
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40200
40300
40400
40500
40600
40700
40800
40900
41000
41100
41200
41300
41400
41500
5
10
15
20
java
You are here!
Your memory usage beats 52.91 % of java submissions.
Memory (KB)
Distribution (%)

40200
40300
40400
40500
40600
40700
40800
40900
41000
41100
41200
41300
41400
41500
5
10
15
20
Zoom area by dragging across this chart

Invite friends to challenge Plus One


Submitted Code: 0 minutes ago

Language: 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
34
35
36
37
38
39
40
class Solution {
public int[] plusOne(int[] digits) {
int carry = 0;
// add one to end of array, calculate carry
int sum = digits[digits.length-1] + 1;
if (sum > 9) {
carry = 1;
digits[digits.length-1] = sum % 10;
}
else {
digits[digits.length-1] = sum;
}
int i = digits.length-2;
// carry the carry through rest of digits
while (i >= 0) {
sum = digits[i] + carry;
if (sum > 9)
carry = 1;
else
carry = 0;
digits[i] = sum % 10;
i--;
}
// if still a carry at leftmost digit, expand
// array and incorporate the 1
if (carry == 1) {
int[] expanded_digits = new int[digits.length+1];
expanded_digits[0] = 1;
for (int j = 1; j < expanded_digits.length; j++)
expanded_digits[j] = digits[j-1];
return expanded_digits;
}
// otherwise, return original array
return digits;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX