算法:双指针系列(一)-代码展示

在这里插入图片描述

class Solution {
public:
    int getNext(int val) {
        int ret = 0;
        while (val > 0) {
            int temp = val % 10;
            ret = temp * temp + ret;
            val /= 10;
        }
        return ret;
    }

    bool isHappy(int n) {
        int fast = getNext(n), slow = n;
        while (fast != 1 && fast != slow) {
            fast = getNext(getNext(fast));
            slow = getNext(slow);
        }
        return fast == 1;
    }
};
上一篇:华为S5735交换机配置脚本


下一篇:【Mybatis篇】Mybatis的注解开发-????@Delete注解