[C++ CODE] Valid Parenthesis #thetealpickle #algorithms #coding #challenge creator Apr 15, 2019 ・1 min read THE TEAL PICKLE CODING CHALLENGE!! Determine whether the input string is valid. I solved this problem with bae (C++). TRY IT 👀 Check out my solution and share yours!! ~ 💻 💻 Discussion (2) Subscribe Image Upload image Templates Templates Editor guide Personal Moderator Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand Lucas • Apr 16 '19 Dropdown menu Copy link Hide I have done like this: bool validateBrackets(const std::string& data) { std::stack<char> brackets; for (const auto& d : data) { if (d == '[' || d == '(' || d == '{') { brackets.push(d); } else if (d == ']') { if (brackets.top() == '[') brackets.pop(); else return false; } else if (d == ')') { if (brackets.top() == '(') brackets.pop(); else return false; } else if(d == '}') { if (brackets.top() == '{') brackets.pop(); else return false; } } return true; } Collapse Expand creator Author • Apr 24 '19 Dropdown menu Copy link Hide yasss 👏👏 I like the direct comparison for the bracket pairings. More efficient than a map 😬😁 Code of Conduct • Report abuse
Discussion (2)
I have done like this:
yasss 👏👏 I like the direct comparison for the bracket pairings. More efficient than a map 😬😁