[Programmers] 쇠막대기

Time Lapse :6min 0sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <vector>

using namespace std;

int solution(string arrangement) {
int answer = 0;
int sticks = 0;
for(int i=0;i<arrangement.length();i++){
if(arrangement[i]=='('){
if(arrangement[i+1]=='(')
++sticks;
else{
answer += sticks;
++i;
}
}
else{
++answer;
--sticks;
}
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/ironStick/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.