#3079
Easy Algorithms Find the sum of encrypted integers
Array Math
74.8% acceptance
Feb 25, 2026
135
20
You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.
Return the sum of encrypted elements.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn sum_of_encrypted_int(nums: Vec<i32>) -> i32 {
nums.iter().map(|&x| {
let s = x.to_string();
let max_d = s.chars().max().unwrap();
s.chars().map(|_| max_d).collect::<String>().parse::<i32>().unwrap()
}).sum()
}
}