标签:style git 递归 sha turn 内存 app ret solution
public class Solution { public int squareSum(int n) { int sum = 0; while(n > 0){ int digit = n % 10; sum += digit * digit; n /= 10; } return sum; } public boolean isHappy(int n) { int slow = n, fast = squareSum(n); while (slow != fast){ slow = squareSum(slow); fast = squareSum(squareSum(fast)); }; return slow == 1; } }
这个想法也太牛了!!我一开始也是想到用递归,考虑到内存可能不狗,没想到这个方法啊。
标签:style git 递归 sha turn 内存 app ret solution
原文地址:https://www.cnblogs.com/doyi111/p/12812260.html