Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isHappy(int ans) {
- int count=0;
- while(ans>1&&count<10)
- {
- int sum=0;
- while(ans>0)
- {
- sum+=(ans%10)*(ans%10);
- //cout<<"***temp%10 "<<temp%10<<endl;
- ans/=10;
- }
- ans=sum;
- count++;
- //cout<<"***"<<ans<<endl;
- }
- if(ans==1)
- return true;
- else
- return false;
- }
- };
Add Comment
Please, Sign In to add comment