-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path202.java
More file actions
29 lines (28 loc) · 718 Bytes
/
Copy path202.java
File metadata and controls
29 lines (28 loc) · 718 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
public class Solution {
public boolean isHappy(int n) {
int i = 0;
int temp = 0;
int di = 0;
HashSet<Integer> set = new HashSet<>();
int magic = 0;
while(true) {
temp = 0;
set.add(n);
while (true) {
di = n % 10;
temp += di * di;
n /= 10;
if (n == 0) {
n = temp;
if (temp == 1) {
return true;
}
if (set.contains(n)) {
return false;
}
break;
}
}
}
}
}