You are given a string ss, consisting of brackets of two types: '(', ')', '[' and ']'. code example
Example: bracket balancing c++
bool correct_paranthesis(string str){
stack<char> stk;
map<char,char> bracket_map;
bracket_map[')'] = '(';
bracket_map['}'] = '{';
bracket_map[']'] = '[';
for(int i=0; i<str.size(); i++){
if(str[i] == '(' || str[i] == '{' || str[i] == '[')
stk.push(str[i]);
if(str[i] == ')' || str[i] == '}' || str[i] == ']'){
if(stk.empty())
return false;
if(stk.top() == bracket_map[str[i]] )
stk.pop();
}
}
return (stk.empty() == true);
}