leetcode练习——栈(1)
生活随笔
收集整理的這篇文章主要介紹了
leetcode练习——栈(1)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題號20:Invalid?Parentheses
Given a string containing just the characters?'(',?')',?'{',?'}',?'['?and?']', determine if the input string is valid.
An input string is valid if:
Note that an empty string is?also considered valid.
Example 1:
Input: "()" Output: trueExample 2:
Input: "(]" Output: false算法
復(fù)雜度分析
- 時(shí)間復(fù)雜度:O(n),因?yàn)槲覀円淮沃槐闅v給定的字符串中的一個(gè)字符并在棧上進(jìn)行?O(1)?的推入和彈出操作。
- 空間復(fù)雜度:O(n),當(dāng)我們將所有的開括號都推到棧上時(shí)以及在最糟糕的情況下,我們最終要把所有括號推到棧上。例如?((((((((((。
?
總結(jié)
以上是生活随笔為你收集整理的leetcode练习——栈(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php伪静态url运用,再谈 THINK
- 下一篇: OpenDDS通讯中rtps_disco