258. 各位相加
https://leetcode-cn.com/problems/add-digits/、
观察法
若num不是9的倍数,则最终结果为num%9 否则结果为9
class Solution:
def addDigits(self, num: int) -> int:
if num == 0: return 0
return num%9 if num%9 else 9
最后更新于
https://leetcode-cn.com/problems/add-digits/、
若num不是9的倍数,则最终结果为num%9 否则结果为9
class Solution:
def addDigits(self, num: int) -> int:
if num == 0: return 0
return num%9 if num%9 else 9
最后更新于