Last active
December 9, 2021 20:28
-
-
Save uzbekdev1/7e0d2804fdbb936dbc8614a0262b22d9 to your computer and use it in GitHub Desktop.
Baseball Game - https://leetcode.com/problems/baseball-game/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testcase:
Run Code Result: