-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestUtils.java
More file actions
67 lines (62 loc) · 1.5 KB
/
Copy pathTestUtils.java
File metadata and controls
67 lines (62 loc) · 1.5 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
package test;
import java.util.*;
public class TestUtils {
public static int JudgeRegx(String s) throws Exception {
Stack<Character> stack = new Stack<Character>();
boolean shuzi = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '0' || c == '1') {
shuzi = true;
} else if (c == '(') {
shuzi = false;
stack.push(c);
} else if (c == ')') {
shuzi = true;
if (stack.empty()) {
return 0;
} else {
stack.pop();
}
} else if (c == '|') {
if (!shuzi)
return 0;
shuzi = false;
} else if (c == '*') {
if (!shuzi)
return 0;
shuzi = false;
} else
return 0;
}
if (stack.empty()) {
return 1;
} else {
return 0;
}
}
public static int calcPLength(int[] intAr) throws Exception {
if (intAr.length <= 1)
return intAr.length;
Arrays.sort(intAr);
int ans = 1;
int[][] dp = new int[intAr.length][10000005];
for (int i = 0; i < intAr.length; i++)
for (int j = 0; j < intAr.length; j++)
dp[i][j] = 1; // 单独成列
for (int i = 1; i < intAr.length; i++) {
for (int j = i - 1; j >= 0; j--) {
int diff = intAr[i] - intAr[j];
dp[i][diff] = dp[j][diff] + 1;
ans = Math.max(ans, dp[i][diff]);
}
}
return ans;
}
public static void main(String[] args) throws Exception {
System.out.println(JudgeRegx("010101101*"));
System.out.println(JudgeRegx("(11|0*)*"));
System.out.println(JudgeRegx(")*111"));
System.out.println(calcPLength(new int[]{3,8,4,5,6,2}));
}
}