Skip to content

Commit

Permalink
leetcode mmistakes#20
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun Oh Lee authored and Jun Oh Lee committed May 6, 2022
1 parent 9546a68 commit 428dd27
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions _posts/algorithm/string/2022-05-04-20-Valid Parenthese.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
layout: single
title: "[string] Leetcode #20 valid parenthese"
categories: ["string"]
tag: [algorithm, string, leetcode]
toc: true
toc_label: "Table of Contents"
toc_icon: "align-justify" # corresponding Font Awesome icon name (without fa prefix)
toc_sticky: true
---

># description of the problem
finding right mate of parenthese

># logic
using the stack method which means `Last in, first out`.

```Python
class Solution:
def isValid(self, s: str) -> bool:
cha ={"(":")","[":"]","{":"}"}
stack = []
for i in range(len(s)):
parenthese = s[i]
if parenthese in cha.keys():
stack.append(parenthese)
else :
if stack == []:
return False
else:
pop = stack.pop()
if parenthese != cha[pop]:
return False
if stack == []:
return True



```

0 comments on commit 428dd27

Please sign in to comment.