-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path955.java
More file actions
67 lines (63 loc) · 2.05 KB
/
955.java
File metadata and controls
67 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int minDeletionSize(String[] A) {
int count = 0, len=A.length;
boolean stop = true;
boolean[] skip=new boolean[len];
boolean[] prev =new boolean[len];
for(int i=0;i<A[0].length();i++){
System.arraycopy(skip, 0, prev, 0, len);
stop = true;
for(int j=1;j<len;j++){
if((!skip[j])&&A[j].charAt(i)<A[j-1].charAt(i)){
count++;
stop=false;
System.arraycopy(prev, 0, skip, 0, len);
break;
}
if((!skip[j])&&A[j].charAt(i)==A[j-1].charAt(i)){
skip[j]=false;
stop=false;
}else{
skip[j]=true;
}
}
if(stop){
return count;
}
}
return count;
}
}
__________________________________________________________________________________________________
sample 37452 kb submission
class Solution {
public int minDeletionSize(String[] A) {
int m = A.length;
int n = A[0].length();
int res = 0;
Set<Integer> set = new HashSet<>();
for (int i = 1; i < m && set.size() < n; i++) {
String s1 = A[i-1];
String s2 = A[i];
for (int j = 0; j < n; j++) {
if (set.contains(j)) {
continue;
}
char c1 = s1.charAt(j);
char c2 = s2.charAt(j);
if (c1 < c2) {
break;
}
if (c1 > c2) {
set.add(j);
i = 0;
break;
}
}
}
return set.size();
}
}
__________________________________________________________________________________________________