Skip to content

Commit c3ac45a

Browse files
committed
Improved task 3213
1 parent 8f3e250 commit c3ac45a

File tree

1 file changed

+3
-1
lines changed
  • src/main/java/g3201_3300/s3213_construct_string_with_minimum_cost

1 file changed

+3
-1
lines changed

src/main/java/g3201_3300/s3213_construct_string_with_minimum_cost/Solution.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public int minimumCost(String target, String[] words, int[] costs) {
8686
dp[0] = 0;
8787
ACAutomaton.Node node = root;
8888
for (int i = 1; i < dp.length; i++) {
89-
node = ac.go(node, target.charAt(i - 1));
89+
if (node != null) {
90+
node = ac.go(node, target.charAt(i - 1));
91+
}
9092
for (ACAutomaton.Node temp = node;
9193
temp != null && temp != root;
9294
temp = ac.getOutput(temp)) {

0 commit comments

Comments
 (0)