编程语言
首页 > 编程语言> > 算法珠玑——双百故事

算法珠玑——双百故事

作者:互联网

https://leetcode-cn.com/problems/happy-number/submissions/

class Solution {
public:
    bool isHappy(int n) {
        short times = 7;
        int num;
        while(n != 1 && --times)
        {
            num = 0;
            while(n) {
                num+=(n%10)*(n%10);
                n/=10;
            }
            n = num;
        }
        if (n == 1) return true;
        return false;
    }
};

标签:10,num,int,n%,times,算法,珠玑,双百,return
来源: https://www.cnblogs.com/qianxinn/p/16130530.html