-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy path0682-BaseballGame.cs
41 lines (37 loc) · 1.15 KB
/
0682-BaseballGame.cs
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
//-----------------------------------------------------------------------------
// Runtime: 92ms
// Memory Usage: 24.3 MB
// Link: https://leetcode.com/submissions/detail/335007706/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _0682_BaseballGame
{
public int CalPoints(string[] ops)
{
var roundPoints = new int[ops.Length];
var index = 0;
foreach (var op in ops)
{
if (op == "C")
index--;
else if (op == "D")
{
roundPoints[index] = roundPoints[index - 1] * 2;
index++;
}
else if (op == "+")
{
roundPoints[index] = roundPoints[index - 1] + roundPoints[index - 2];
index++;
}
else
roundPoints[index++] = int.Parse(op);
}
var sum = 0;
for (int i = 0; i < index; i++)
sum += roundPoints[i];
return sum;
}
}
}