β¨ thetealpickle π± Posted on Apr 15, 2019 [C++ CODE] Valid Parenthesis #thetealpickle #algorithms #coding #challenge 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!! ~ π» π» Top comments (2) Subscribe Submit Preview Dismiss Collapse Expand Lucas Lucas Lucas Follow CS student, software developer, and sometimes gamer. Location Santa Catarina, Brasil Work Web Developer at GeekHunter Joined Dec 6, 2018 • 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 β¨ thetealpickle π± β¨ thetealpickle π± β¨ thetealpickle π± Follow π±Senior iOS and Backend Engineer π₯ building [π²π»πβοΈπΊ] and training [π₯] Founder @thetealpickleco Email jessica@thetealpickle.com Location New York City Education Computer Engineering @ New York University Work Senior iOS and Backend Engineer, THETEALPICKLE Joined Aug 16, 2017 • 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
Top comments (2)
I have done like this:
yasss ππ I like the direct comparison for the bracket pairings. More efficient than a map π¬π