Delete Columns to Make Sorted II LeetCode solution in Java

1
class Solution {
2
public int minDeletionSize(String[] strs) {
3
boolean[] sorted = new boolean[strs.length];
4
int res = 0;
5
for (int i = 0; i < strs[0].length(); i++) {
6
int j = 0;
7
for (; j < strs.length - 1; j++) {
8
if (!sorted[j] && strs[j].charAt(i) > strs[j + 1].charAt(i)) {
9
res++;
10
break;
11
}
12
}
13
if (j < strs.length - 1) {
14
continue;
15
}
16
j = 0;
17
for (; j < strs.length - 1; j++) {
18
if (strs[j].charAt(i) < strs[j + 1].charAt(i)) {
19
sorted[j] = true;
20
}
21
}
22
}
23
return res;
24
}
25
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0