/
Solution1898.java
46 lines (35 loc) · 1.27 KB
/
Solution1898.java
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
package answers.Q1800_1899.Q1898_Maximum_Number_of_Removable_Characters;
import com.nj.algo.search.NJSearchAble;
import com.nj.algo.search.NJBinarySearch;
import com.nj.lang.NJString;
import java.util.Set;
import java.util.HashSet;
public class Solution1898 {
class Removal implements NJSearchAble {
final String s;
final String p;
final int[] removable;
Removal(final String s, final String p, int[] removable) {
this.s = s;
this.p = p;
this.removable = removable;
}
public boolean ifMeet(int k) {
String s1;
if (k == 0) return true;
s1 = NJString.delAllPos(s, removable, k);
boolean ret = NJString.isSubStrOf(p, s1);
//// if (ret)
//// System.out.println("k=" + k + ": p=" + p + " is substring of s1=" + s1);
//// else
//// System.out.println("k=" + k + ": p=" + p + " is NOT substring of s1=" + s1);
return ret;
}
}
public int maximumRemovals(String s, String p, int[] removable) {
Removal rv = new Removal(s, p, removable);
NJBinarySearch bs = new NJBinarySearch();
int k = bs.biggestMeet(rv, 0, removable.length);
return k;
}
}