Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit49fff18

Browse files
committed
Create: 0682-baseball-game
1 parentd988919 commit49fff18

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

‎csharp/0682-baseball-game.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
publicclassSolution{
2+
publicintCalPoints(string[]operations){
3+
List<int>stack=new();
4+
5+
foreach(varoperationinoperations)
6+
{
7+
switch(operation)
8+
{
9+
case"D":
10+
stack.Add(stack[stack.Count()-1]*2);
11+
break;
12+
case"+":
13+
stack.Add(stack[stack.Count()-1]+stack[stack.Count()-2]);
14+
break;
15+
case"C":
16+
stack.RemoveAt(stack.Count()-1);
17+
break;
18+
default:
19+
stack.Add(int.Parse(operation));
20+
break;
21+
}
22+
}
23+
24+
returnstack.Sum();
25+
}
26+
}

‎javascript/0682-baseball-game.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
*@param {string[]} operations
3+
*@return {number}
4+
*/
5+
varcalPoints=function(operations){
6+
conststack=[];
7+
for(constopofoperations){
8+
if(op==="+"){
9+
stack.push(stack[stack.length-1]+stack[stack.length-2]);
10+
}elseif(op==="C"){
11+
stack.pop()
12+
}elseif(op==="D"){
13+
stack.push(stack[stack.length-1]*2);
14+
}else{
15+
stack.push(parseInt(op))
16+
}
17+
}
18+
returnstack.reduce((prev,curr)=>prev+curr,0)
19+
};

‎swift/0682-baseball-game.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution{
2+
func calPoints(_ operations:[String])->Int{
3+
varscoreArray=[Int]()
4+
foriin0..<operations.count{
5+
ifoperations[i]=="C"{
6+
scoreArray.removeLast()
7+
}elseifoperations[i]=="D"{
8+
scoreArray.append(scoreArray.last!*2)
9+
}elseifoperations[i]=="+"{
10+
scoreArray.append(scoreArray[scoreArray.count-2]+ scoreArray[scoreArray.count-1])
11+
}else{
12+
scoreArray.append(Int(operations[i])!)
13+
}
14+
}
15+
return scoreArray.isEmpty?0: scoreArray.reduce(0,+)
16+
}
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp