What is the problem with this solution?


  • -1
    V
    class Solution {
    public:
        bool isHappy(int n) {
            string num = to_string(n) ;
            int sum = 0 ;
            for(int i = 0 ; i < num.size() ; i++) {
          
                sum = sum + pow(num[i],2) ;
            }
            if(sum==1)
            return true ;
            else
            return isHappy(sum);
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.