My leetcode submissions.
at main 900 B view raw
1/* ======================================================================== 2 * 3 * Filename: 4 * Description: 5 * Author: 6 * Version: 0.0.1 7 * 8 * ======================================================================== */ 9#include <iostream> 10#include <string> 11#include <stack> 12 13auto main() -> int 14{ 15 std::cout << "Hello world!\n"; 16 return 0; 17} 18 19class Solution { 20public: 21 bool isValid(std::string s) { 22 auto st = std::stack<char>(); 23 24 for (const auto& ch : s) { 25 char check = '\0'; 26 switch (ch) { 27 case '(': 28 case '{': 29 case '[': 30 st.push(ch); 31 continue; 32 case ')': 33 check = '('; 34 break; 35 case '}': 36 check = '{'; 37 break; 38 case ']': 39 check = '['; 40 break; 41 default: continue; 42 } 43 if (not st.empty()) { 44 if (st.top() == check) 45 st.pop(); 46 else 47 return false; 48 } else { 49 return false; 50 } 51 52 53 } 54 55 return st.empty(); 56 } 57};