class Solution:
def isArmstrong(self, n: int) -> bool:
def getSumOfKthPowerOfDigits(num, k):
result = 0
while num != 0:
result += (num % 10) ** k
num //= 10
return result
length = len(str(n))
return getSumOfKthPowerOfDigits(n, length) == nTime complexity:
Space complexity: constant space
Where is the number of digits in the input integer
n.
class Solution:
def isArmstrong(self, n: int) -> bool:
def getSumOfKthPowerOfDigits(num, k):
result = 0
while num != 0:
result += (num % 10) ** k
num //= 10
return result
length = int(math.log10(n)) + 1
return getSumOfKthPowerOfDigits(n, length) == nTime complexity:
Space complexity: constant space
Where is the number of digits in the input integer
n.
class Solution:
def isArmstrong(self, n: int) -> bool:
def getSumOfKthPowerOfDigits(num, k):
result = 0
while num != 0:
result += (num % 10) ** k
num //= 10
return result
length = 0
temp_n = n
while temp_n != 0:
length += 1
temp_n //= 10
return getSumOfKthPowerOfDigits(n, length) == nTime complexity:
Space complexity: constant space
Where is the number of digits in the input integer
n.