[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"$fe-u8RnuEXz9qlEEeUTvlHEziZa1Ff4ZPcdvBvWtftTs":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"title":8,"category":9,"problemHtml":10,"solutions":11,"repoUrl":20},"Validate Parentheses","Data Structures & Algorithms","",[12,16],{"lang":13,"label":14,"html":15},"java","Java","\u003Cpre>\u003Ccode class=\"language-java\">class Solution {\n    public boolean isValid(String s) {\n        Stack&lt;Character&gt; stack = new Stack&lt;&gt;();\n        Map&lt;Character, Character&gt; map = new HashMap&lt;&gt;();\n        map.put(&#39;)&#39;, &#39;(&#39;);\n        map.put(&#39;}&#39;, &#39;{&#39;);\n        map.put(&#39;]&#39;, &#39;[&#39;);\n\n        for (char c : s.toCharArray()) {\n            if (!map.containsKey(c))\n                stack.push(c);\n\n            else {\n                if (!stack.isEmpty()) {\n                    if (stack.peek() != map.get(c))\n                        return false;\n                    stack.pop();\n                } else {\n                    return false;\n                }\n            }\n        }\n\n        return stack.isEmpty();\n    }\n}\u003C\u002Fcode>\u003C\u002Fpre>",{"lang":17,"label":18,"html":19},"python","Python","\u003Cpre>\u003Ccode class=\"language-python\">class Solution:\n    def isValid(self, s: str) -&gt; bool:\n        stack = []\n        parenthDict = {&quot;}&quot;: &quot;{&quot;, &quot;)&quot;: &quot;(&quot;, &quot;]&quot;: &quot;[&quot;}\n\n        for c in s:\n            if c in parenthDict:\n                if stack and stack[-1] == parenthDict[c]:\n                    stack.pop()\n                else:\n                    return False\n            else:\n                stack.append(c)\n\n        return True if not stack else False\u003C\u002Fcode>\u003C\u002Fpre>","https:\u002F\u002Fgithub.com\u002Fvishwarajsali\u002FInterviewPrep\u002Ftree\u002Fmain\u002FData%20Structures%20%26%20Algorithms%2Fvalidate-parentheses"]