2496. Maximum Value of a String in an Array Easy

@problem@discussion
#Array#String



1/**
2 * [2496] Maximum Value of a String in an Array
3 *
4 * The value of an alphanumeric string can be defined as:
5 * 
6 * 	The numeric representation of the string in base 10, if it comprises of digits only.
7 * 	The length of the string, otherwise.
8 * 
9 * Given an array strs of alphanumeric strings, return the maximum value of any string in strs.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: strs = ["alic3","bob","3","4","00000"]
14 * Output: 5
15 * Explanation: 
16 * - "alic3" consists of both letters and digits, so its value is its length, i.e. 5.
17 * - "bob" consists only of letters, so its value is also its length, i.e. 3.
18 * - "3" consists only of digits, so its value is its numeric equivalent, i.e. 3.
19 * - "4" also consists only of digits, so its value is 4.
20 * - "00000" consists only of digits, so its value is 0.
21 * Hence, the maximum value is 5, of "alic3".
22 * 
23 * <strong class="example">Example 2:
24 * 
25 * Input: strs = ["1","01","001","0001"]
26 * Output: 1
27 * Explanation: 
28 * Each string in the array has value 1. Hence, we return 1.
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= strs.length <= 100
34 * 	1 <= strs[i].length <= 9
35 * 	strs[i] consists of only lowercase English letters and digits.
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/
41// discuss: https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn maximum_value(strs: Vec<String>) -> i32 {
47        0
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_2496() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.