Submission Detail

406 / 406 test cases passed.
Status:

Accepted

Runtime: 2 ms
Memory Usage: 40.3 MB
Submitted: 1 hour, 14 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
2
4
6
8
10
12
14
16
18
20
40
60
80
java
You are here!
Your runtime beats 16.97 % of java submissions.
Runtime (ms)
Distribution (%)

Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

39500
38500
38750
39000
39250
39750
40000
40250
40500
2.5
5.0
7.5
10.0
12.5
java
You are here!
Your memory usage beats 11.84 % of java submissions.
Memory (KB)
Distribution (%)

39500
38500
38750
39000
39250
39750
40000
40250
40500
5
10
Zoom area by dragging across this chart

Invite friends to challenge Happy Number


Submitted Code: 1 hour, 14 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Solution {
public boolean isHappy(int n) {
int s = 0;
int[] seen = new int[200];
boolean loop = false;
while (n != 1) {
// loop detection
for (int x = 0; x < seen.length; x++)
if (seen[x] == n)
loop = true;
if (loop == true)
return false;
seen[s++] = n;
int size = 0;
int temp = n;
// determine # of digits
while (temp >= 1) {
temp /= 10;
size++;
}
int[] digits = new int[size];
int i = 0;
if (n > 9) {
// store the individual digits in an array
while (n >= 1) {
digits[i] = (int)(n % 10);
n /= 10;
i++;
}
} else {
digits[0] = n;
}
n = 0;
// square the digits and add
for (int k = 0; k < digits.length; k++)
n += digits[k]*digits[k];
}
return true;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX