Skip to content

Commit 6eedbe9

Browse files
authored
Added solution for 2496
1 parent 6dc891d commit 6eedbe9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::cmp::max;
2+
3+
impl Solution {
4+
// Loop through the vector of strings. Keep a track of whether we found a non-digit in each iterated string. If we did, compare its length with the highest value we found so far. If we didn't find any non-digit in the iterated string, convert it into a i32 and compare its value with the highest value we found so far.
5+
pub fn maximum_value(strs: Vec<String>) -> i32 {
6+
let mut result = 0;
7+
8+
for string_iterator in strs {
9+
let mut found_a_non_digit = false;
10+
for ch in string_iterator.chars() {
11+
let ascii_value = ch as usize;
12+
13+
// The ASCII value of English numbers is 48 to 57
14+
if ascii_value < 48 || ascii_value > 57 {
15+
result = max(result, (string_iterator.len() as i32));
16+
found_a_non_digit = true;
17+
break;
18+
}
19+
}
20+
21+
if !found_a_non_digit {
22+
result = max(result, (string_iterator.parse::<i32>().unwrap()));
23+
}
24+
}
25+
return result;
26+
}
27+
}

0 commit comments

Comments
 (0)