leetcode-第五场双周赛-1134-阿姆斯特朗数

第一次提交:

class Solution:
    def isArmstrong(self, N: int) -> bool:
        n = N
        l = len(str(N))
        res = 0
        while N:
            a = N % 10
            res += a**l
            N = N//10
        if res == n:
            return True
        return False

另:

class Solution:
    def isArmstrong(self, N: int) -> bool:
        s=str(N)
        l=len(s)
        tmp=0
        for c in s:
            tmp+=int(c)**l
        return True if tmp==N else False

 

posted @ 2019-07-30 16:13  oldby  阅读(175)  评论(0编辑  收藏  举报