[
math
string
]
Leetcode 1134 Armstrong Number
Problem statement
https://leetcode.com/problems/armstrong-number/
Solution
Just iterate through our number and check condition.
Complexity
Time and space complexity is O(m)
, where m
is the length of n
.
Code
class Solution:
def isArmstrong(self, n):
s = str(n)
return sum(int(i)**len(s) for i in s) == n