Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
Thank you bro
Table of Contents0:00 Problem Statement0:42 Solution4:32 Pseudo Code7:38 Code - Python8:54 Code - C++
class Solution{ public: static char opening_bracket(char closing) { if (closing == ')') return '('; if (closing == '}') return '{'; if (closing == ']') return '['; } bool ispar(string x) { stack st; for (auto &ch: x) { if (ch == '(' or ch == '{' or ch == '[') st.push(ch); else { if (st.empty()) return false; char st_bracket = st.top(); char str_bracket = opening_bracket(ch); if (st_bracket != str_bracket) return false; st.pop(); } } if (st.empty()) return true; return false; }};
Thank you bro
Table of Contents
0:00 Problem Statement
0:42 Solution
4:32 Pseudo Code
7:38 Code - Python
8:54 Code - C++
class Solution
{
public:
static char opening_bracket(char closing) {
if (closing == ')')
return '(';
if (closing == '}')
return '{';
if (closing == ']')
return '[';
}
bool ispar(string x)
{
stack st;
for (auto &ch: x) {
if (ch == '(' or ch == '{' or ch == '[')
st.push(ch);
else {
if (st.empty())
return false;
char st_bracket = st.top();
char str_bracket = opening_bracket(ch);
if (st_bracket != str_bracket)
return false;
st.pop();
}
}
if (st.empty())
return true;
return false;
}
};