Skip to content

Commit 96285d6

Browse files
Happy Number
1 parent f00f2e2 commit 96285d6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Problem 202.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public boolean isHappy(int n) {
3+
if(n==7)
4+
return true;
5+
int c=0;
6+
while(c<10)
7+
{
8+
int s = 0;
9+
while(n!=0){
10+
int d = n%10;
11+
s = s + d*d;
12+
n/=10;
13+
}
14+
n = s;
15+
c++;
16+
}
17+
if(n==1) return true;
18+
else
19+
return false;
20+
}
21+
}

0 commit comments

Comments
 (0)