1134. Armstrong Number ¶ Time: $O(\log n)$ Space: $O(\log n)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10class Solution { public: bool isArmstrong(int n) { const string s = to_string(n); const int k = s.length(); for (const char c : s) n -= pow(c - '0', k); return n == 0; } }; 1 2 3 4 5 6 7 8 9class Solution { public boolean isArmstrong(int n) { final String s = String.valueOf(n); final int k = s.length(); for (final char c : s.toCharArray()) n -= Math.pow(c - '0', k); return n == 0; } } 1 2 3 4 5class Solution: def isArmstrong(self, n: int) -> bool: s = str(n) k = len(s) return sum(pow(int(c), k) for c in s) == n