close
Given an integer number n, return the difference between the product of its digits and the sum of its digits. 解題: 大於九除十,餘數與p相乘,與s相加 小於九不遞迴 可是使用較多變數似乎不是好的code python code:
class Solution: def subtractProductAndSum(self, n: int) -> int: p,s=1,0 while n>9: p*=n%10 s+=n%10 n=n//10 p*=n s+=n return p-s
文章標籤
全站熱搜
留言列表