Create Happy Number

pull/986/head
SHITHIN SHETTY 2022-10-08 15:50:22 +05:30 committed by GitHub
parent 3c7339e59c
commit ffaf9b42c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
class Solution{
public:
int isHappy(int N){
int sum=0,r;
while(N!=0)
{
r=N%10;
sum=sum+(r*r);
N=N/10;
}
if(sum==1)
return 1;
else if(sum<10)
return 0;
else
return isHappy(sum);
}
};