Solve 944. Delete Columns to Make Sorted
This commit is contained in:
parent
1d06cbd973
commit
4919cb9540
22
rust/944_delete_columns_to_make_sorted.rs
Normal file
22
rust/944_delete_columns_to_make_sorted.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
impl Solution {
|
||||||
|
pub fn min_deletion_size(strs: Vec<String>) -> i32 {
|
||||||
|
let string_length = strs[0].len();
|
||||||
|
let num_strs = strs.len();
|
||||||
|
let mut count = 0;
|
||||||
|
|
||||||
|
for i in 0..string_length {
|
||||||
|
let mut current = '\0';
|
||||||
|
for j in 0..num_strs {
|
||||||
|
let c = strs[j].chars().nth(i).unwrap();
|
||||||
|
if c < current {
|
||||||
|
count += 1;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user