zoukankan      html  css  js  c++  java
  • [LeetCode] Valid Palindrome

    代码:

    class Solution {
    public:
        bool isValid(string s) {
            string left = "([{";
            string right = ")]}";
            stack<char> stk;
    
            for(auto c : s) {
                if(left.find(c) != string::npos)
                    stk.push(c);
                else {
                    if(stk.empty() || stk.top() != left[right.find(c)])
                        return false;
                    else
                        stk.pop();
                }
            }
    
            return stk.empty();
        }
    };

    杂记:

    1. string::npos

    2. 其他解法一

    不使用占,递归替换符号

  • 相关阅读:
    052-90
    052-89
    052-88
    052-87
    052-86
    html5的manifest
    js中数字转金钱格式
    CSS复合样式
    资料
    异步
  • 原文地址:https://www.cnblogs.com/Azurewing/p/4310032.html
Copyright © 2011-2022 走看看