leecode202,快乐数,环形链表法,带循环的规律都可以考虑用环形链表文章来源:https://www.toymoban.com/news/detail-480467.html
class Solution: def isHappy(self, n: int) -> bool: def get_next(number): total_sum = 0 while number!= 0: tmp = number%10 number //= 10 total_sum += tmp**2 return total_sum s = n f = get_next(n) while f != 1 and f != s: s = get_next(s) f = get_next(get_next(f)) return f == 1
leecode258,各位相加,数根,找数学规律文章来源地址https://www.toymoban.com/news/detail-480467.html
class Solution: def addDigits(self, num: int) -> int: return (num-1)%9+1 if num else 0
到了这里,关于leecode的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!