requirements

Suppose there is a k-digit number N, each of which has a sum of N to the k power, then this number is an Amstrang number.

You are given a positive integer N to determine whether it is an Armstrong number, returning true if it is, false if it is not.

Example 1:

Input: 153 Output: true Example: 153 is a three-digit number and 153 = 1^3 + 5^3 + 3^3.Copy the code

Example 2:

Input: 123 Output: false Description: 123 is a three-digit number and 123! Lambda is equal to 1^3 + 2^3 + 3^3 = 36.Copy the code

The core code

class Solution:
    def isArmstrong(self, n: int) - >bool:
        k = len(str(n))
        _n = n
        s = 0
        while n:
            n,tmp = divmod(n,10)
            s += tmp ** k
        return s == _n
Copy the code

This topic and other xx number of questions, according to the rules can be handled, relatively simple.