One minute
Leetcode 944
944. Delete Columns to Make Sorted
This solution loops through every column, and then if the previous letter in the column is greater than the current letter, we know that this column can be removed.
func minDeletionSize(strs []string) int {
res := 0
for i := 0; i < len(strs[0]); i++ {
for j := 1; j < len(strs); j++ {
if strs[j][i] < strs[j-1][i] {
res++
break
}
}
}
return res
}
Read other posts