博客
关于我
LeetCode刷题(6)--有效的括号
阅读量:143 次
发布时间:2019-02-26

本文共 884 字,大约阅读时间需要 2 分钟。

?????????????????????????????????????????????????

  • ???????

    • ???????????? true?
    • ??????????????? false??????????
  • ?????

    • ?? stack<char> ??????????????
  • ??????

    • ?????????????
      • ?????? ('(', '{', '[')??????????????
      • ?????? (')', '}', ']')??????????????
        • ????????????? false?
        • ???????????????
  • ??????

    • ?????????????????????????? false?
    • ????? true?
  • ?????????????????????????????????? O(n)??? n ?????????????? O(n)?

    #include 
    #include
    using namespace std;bool EffectiveBrackets(string s) { if (s.empty()) return true; if (s.size() % 2 != 0) return false; stack
    st; for (char c : s) { if (c == '(' || c == '{' || c == '[') { st.push(c == '(' ? ')' : (c == '{' ? '}' : ']')); } else { if (st.empty() || st.top() != c) { return false; } st.pop(); } } return st.empty();}

    转载地址:http://kiuy.baihongyu.com/

    你可能感兴趣的文章
    UML— 用例图
    查看>>
    Oracle Schema Objects——Tables——Table Compression
    查看>>
    oracle scott趣事
    查看>>
    oracle script
    查看>>
    Oracle select表要带双引号的原因
    查看>>
    Oracle SOA Suit Adapter
    查看>>
    Oracle Spatial GeoRaster 金字塔栅格存储
    查看>>
    Oracle spatial 周边查询SQL
    查看>>
    Oracle Spatial空间数据库建立
    查看>>
    UML— 活动图
    查看>>
    oracle sqlplus已停止工作,安装完成客户端后sqlplus报“段错误”
    查看>>
    oracle SQLserver 函数
    查看>>
    oracle sql分组(group,根据多个内容分组)在select之后from之前 再进行select查询,复杂子查询的使用
    查看>>
    UML— 时序图
    查看>>
    Oracle Statspack分析报告详解(一)
    查看>>
    oracle tirger_在Oracle中,临时表和全局临时表有什么区别?
    查看>>
    Oracle Validated Configurations 安装使用 说明
    查看>>
    oracle where 条件的执行顺序分析1
    查看>>
    oracle 中的 CONCAT,substring ,MINUS 用法
    查看>>
    Oracle 中的 decode
    查看>>