Skip to content

Commit

Permalink
Create 23-maximum-value-of-a-string-in-an-array.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 23, 2023
1 parent 6f841eb commit bd1bf2b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2023/06/23-maximum-value-of-a-string-in-an-array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
impl Solution {
pub fn maximum_value(strs: Vec<String>) -> i32 {
strs.into_iter()
.map(|s| {
let mut cur = 0;
for c in s.chars() {
if c.is_digit(10) {
cur = cur * 10 + c.to_digit(10).unwrap() as i32;
} else {
return s.len() as i32;
}
}
cur
})
.max()
.unwrap_or(0)
}
}

0 comments on commit bd1bf2b

Please sign in to comment.