Skip to main content
Back to problems
#2496
Easy Algorithms

Maximum value of a string in an array

Array String
74.1% acceptance
Feb 25, 2026
435
24
The value of an alphanumeric string: If it consists only of digits → its numeric value (base 10). Otherwise → its length. Given strs, return the maximum value of any string.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn maximum_value(strs: Vec<String>) -> i32 {
    strs.iter().map(|s| {
      if s.chars().all(|c| c.is_ascii_digit()) {
        s.parse::<i32>().unwrap()
      } else {
        s.len() as i32
      }
    }).max().unwrap()
  }
}