Skip to main content
Back to problems
#1134
Easy Algorithms

Armstrong number

Math
77.9% acceptance
Mar 31, 2026
216
20
Given an integer n, return true if and only if it is an Armstrong number. The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn is_armstrong(n: i32) -> bool {
    let s = n.to_string();
    let k = s.len() as u32;
    let sum: i64 = s.bytes().map(|b| ((b - b'0') as i64).pow(k)).sum();
    sum == n as i64
  }
}