class Solution {
public:
string minRemoveToMakeValid(string s) {
stack st;
int cnt=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='(')
{
cnt++;
}
if(cnt==0 && s[i]==')')
{
continue;
}
else
{
st.push(s[i]);
}
if(cnt>0 && s[i]==')')
{
cnt--;
}
}
string ans = "";
while(!st.empty())
{
if(cnt!=0 && st.top()=='(')
{
cnt--;
}
else
{
ans = st.top() + ans;
}
st.pop();
}
return ans;
}
};
This is giving TLE why?