Skip to content

Commit 0f21073

Browse files
refactor 944
1 parent f77b4ce commit 0f21073

File tree

1 file changed

+15
-52
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+15
-52
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,21 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 944. Delete Columns to Make Sorted
5-
*
6-
* We are given an array A of N lowercase letter strings, all of the same length.
7-
* Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.
8-
* For example, if we have an array A = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3},
9-
* then the final array after deletions is ["bef", "vyz"], and the remaining columns of A are ["b","v"], ["e","y"],
10-
* and ["f","z"]. (Formally, the c-th column is [A[0][c], A[1][c], ..., A[A.length-1][c]].)
11-
*
12-
* Suppose we chose a set of deletion indices D such that after deletions, each remaining column in A is in non-decreasing sorted order.
13-
*
14-
* Return the minimum possible value of D.length.
15-
*
16-
* Example 1:
17-
*
18-
* Input: ["cba","daf","ghi"]
19-
* Output: 1
20-
* Explanation:
21-
* After choosing D = {1}, each column ["c","d","g"] and ["a","f","i"] are in non-decreasing sorted order.
22-
* If we chose D = {}, then a column ["b","a","h"] would not be in non-decreasing sorted order.
23-
* Example 2:
24-
*
25-
* Input: ["a","b"]
26-
* Output: 0
27-
* Explanation: D = {}
28-
* Example 3:
29-
*
30-
* Input: ["zyx","wvu","tsr"]
31-
* Output: 3
32-
* Explanation: D = {0, 1, 2}
33-
*
34-
*
35-
* Note:
36-
*
37-
* 1 <= A.length <= 100
38-
* 1 <= A[i].length <= 1000
39-
* */
403
public class _944 {
41-
public static class Solution1 {
42-
public int minDeletionSize(String[] A) {
43-
if (A == null || A.length == 0) {
44-
return 0;
45-
}
46-
int deletion = 0;
47-
for (int i = 0; i < A[0].length(); i++) {
48-
for (int j = 0; j < A.length - 1; j++) {
49-
if (A[j].charAt(i) > A[j + 1].charAt(i)) {
50-
deletion++;
51-
break;
52-
}
4+
public static class Solution1 {
5+
public int minDeletionSize(String[] A) {
6+
if (A == null || A.length == 0) {
7+
return 0;
8+
}
9+
int deletion = 0;
10+
for (int i = 0; i < A[0].length(); i++) {
11+
for (int j = 0; j < A.length - 1; j++) {
12+
if (A[j].charAt(i) > A[j + 1].charAt(i)) {
13+
deletion++;
14+
break;
15+
}
16+
}
17+
}
18+
return deletion;
5319
}
54-
}
55-
return deletion;
5620
}
57-
}
5821
}

0 commit comments

Comments
 (0)