Skip to main content
Back to problems
#1085
Easy Algorithms

Sum of digits in the minimum number

Array Math
76.7% acceptance
Mar 31, 2026
121
151
Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn sum_of_digits(nums: Vec<i32>) -> i32 {
    let min = *nums.iter().min().unwrap();
    let digit_sum: i32 = min.to_string().bytes().map(|b| (b - b'0') as i32).sum();
    if digit_sum % 2 == 0 { 1 } else { 0 }
  }
}