Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process:starting with any positive integer and replace the number by the Sum of the squares of its digits, and repeat the process until the number equals 1 (where it would stay), or it loops Endl essly in a cycle which does not include 1. Those numbers for which this process ends in 1 is happy numbers.
Example:19 is a happy number
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
1 classSolution {2 Public:3 intCnt=0;4 5 intSum (intm)6 {7cnt++;8 intsum=0;9 inttmp=0;Ten while(m>0) One { Atmp=m%Ten; -SUM=SUM+POW (TMP,2); -m=m/Ten; the } - if(sum==1) - { - return 1; + } - if(cnt>= -&&sum!=1) + { A return 0; at } - - sum (sum); - } - - BOOLIshappy (intN) { in if(n==0)return false; - to if(Sum (n) = =1)return true; + if(Sum (n) = =0)return false; - } the};
"Leetcode" Happy number