Skip to content

Commit f37ed97

Browse files
authored
Create Calculate Score After Performing Instructions.java
1 parent 4a81fa9 commit f37ed97

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public long calculateScore(String[] instructions, int[] values) {
3+
long result = 0;
4+
int n = values.length;
5+
int idx = 0;
6+
Set<Integer> executed = new HashSet<>();
7+
while (idx < n && idx >= 0) {
8+
if (!executed.add(idx)) {
9+
break;
10+
}
11+
if (instructions[idx].equals("add")) {
12+
result += values[idx++];
13+
} else {
14+
idx += values[idx];
15+
}
16+
}
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)