Easy solution cpp using stack


#1

Comment body goes here./* … When you try your best but you don’t succeed
When you get what you want but not what you need
When you feel so tired but you can’t sleep
Stuck in reverse
When the tears come streaming down your face
'Cause you lose something you can’t replace
When you love someone but it goes to waste
What could it be worse?
Lights will guide you home
And ignite your bones
And I will try to fix you… -COLDPLAY */

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef double db;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector vi;
typedef vector vl;
typedef vector vd;
typedef vector vpi;
typedef vector vpl;
typedef vector vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define em empty
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#include
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353
const int MOD2=998244353;
const int N = 2e5+5;
const int INF = INT_MAX;

int Solution::solve(string A){
int n=sz(A);
stacks;
int ans=1;
s.push(A[0]);
for(int i=1;i<n;i++){
if(!s.empty() && A[i]==’)’ && s.top()==’(’) s.pop();
else s.push(A[i]);
}

return s.size();

}