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