Skip to content

Commit 0ea7c26

Browse files
committed
modify code
1 parent acb2d7c commit 0ea7c26

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/class044/Code03_TrieTree.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class Code03_TrieTree {
2525

2626
public static int cnt;
2727

28+
public static void build() {
29+
cnt = 1;
30+
}
31+
2832
public static void insert(String word) {
2933
int cur = 1;
3034
pass[cur]++;
@@ -78,6 +82,14 @@ public static int prefixNumber(String pre) {
7882
return pass[cur];
7983
}
8084

85+
public static void clear() {
86+
for (int i = 1; i <= cnt; i++) {
87+
Arrays.fill(tree[i], 0);
88+
end[i] = 0;
89+
pass[i] = 0;
90+
}
91+
}
92+
8193
public static int m, op;
8294

8395
public static String[] splits;
@@ -87,7 +99,7 @@ public static void main(String[] args) throws IOException {
8799
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
88100
String line = null;
89101
while ((line = in.readLine()) != null) {
90-
cnt = 1;
102+
build();
91103
m = Integer.valueOf(line);
92104
for (int i = 1; i <= m; i++) {
93105
splits = in.readLine().split(" ");
@@ -102,11 +114,7 @@ public static void main(String[] args) throws IOException {
102114
out.println(prefixNumber(splits[1]));
103115
}
104116
}
105-
for (int i = 1; i <= cnt; i++) {
106-
Arrays.fill(tree[i], 0);
107-
end[i] = 0;
108-
pass[i] = 0;
109-
}
117+
clear();
110118
}
111119
out.flush();
112120
in.close();

src/class045/Code01_CountConsistentKeys.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class Code01_CountConsistentKeys {
2020

2121
public static int cnt;
2222

23+
public static void build() {
24+
cnt = 1;
25+
}
26+
2327
public static int path(char cha) {
2428
if (cha == '#') {
2529
return 10;
@@ -55,8 +59,15 @@ public static int count(String pre) {
5559
return pass[cur];
5660
}
5761

62+
public static void clear() {
63+
for (int i = 1; i <= cnt; i++) {
64+
Arrays.fill(tree[i], 0);
65+
pass[i] = 0;
66+
}
67+
}
68+
5869
public static int[] countConsistentKeys(int[][] b, int[][] a) {
59-
cnt = 1;
70+
build();
6071
StringBuilder builder = new StringBuilder();
6172
for (int[] nums : a) {
6273
builder.setLength(0);
@@ -74,10 +85,7 @@ public static int[] countConsistentKeys(int[][] b, int[][] a) {
7485
}
7586
ans[i] = count(builder.toString());
7687
}
77-
for (int i = 1; i <= cnt; i++) {
78-
Arrays.fill(tree[i], 0);
79-
pass[i] = 0;
80-
}
88+
clear();
8189
return ans;
8290
}
8391

0 commit comments

Comments
 (0)