Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Last active December 9, 2021 20:28
Show Gist options
  • Save uzbekdev1/7e0d2804fdbb936dbc8614a0262b22d9 to your computer and use it in GitHub Desktop.
Save uzbekdev1/7e0d2804fdbb936dbc8614a0262b22d9 to your computer and use it in GitHub Desktop.
public class Solution {
public int CalPoints(string[] ops) {
var score = new List<int>();
for (int i = 0; i < ops.Length; i++)
{
string c = ops[i];
if (c == "+")
{
score.Add(score[^1] + score[^2]);
}
else if (c == "D")
{
score.Add(score[^1] * 2);
}
else if (c == "C")
{
score.RemoveAt(score.Count - 1);
}
else
{
score.Add(int.Parse(c));
}
}
return score.Sum();
}
}
@uzbekdev1
Copy link
Author

Testcase:

image


Run Code Result:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment