-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path202.java
More file actions
33 lines (33 loc) · 989 Bytes
/
202.java
File metadata and controls
33 lines (33 loc) · 989 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
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public boolean isHappy(int n) {
if (n < 10){
if (n == 1 || n == 7) return true;
else return false;
}else{
double y = 0;
while (n > 0){
y += Math.pow(n%10,2);
n /= 10;
}
return isHappy((int)y);
}
}
}
__________________________________________________________________________________________________
sample 31804 kb submission
class Solution {
public boolean isHappy(int n) {
while (n >= 10) {
int sum = 0;
while (n > 0) {
sum += (n % 10) * (n % 10);
n = n / 10;
}
n = sum;
}
return n == 1 || n == 7;
}
}
__________________________________________________________________________________________________