Skip to content

Commit b483d9c

Browse files
committed
doc: add info
1 parent 9fa1016 commit b483d9c

File tree

1 file changed

+10
-2
lines changed
  • src/leet-code/0020-valid-parentheses

1 file changed

+10
-2
lines changed

src/leet-code/0020-valid-parentheses/README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Valid Parentheses
22

3-
Given a string `str` containing just the characters `'('`, `')'`, `'['`, `']'`,
4-
`'{'`, `'}'`, determine if the string is valid.
3+
Given a string `str` consisting of the following characters: `'('`, `')'`,
4+
`'['`, `']'`, `'{'`, `'}'`, determine if `str` is valid.
55

66
* Open brackets must be closed by the same type of brackets.
77
* Open brackets must be closed in the correct order.
@@ -38,3 +38,11 @@ Out: true
3838
In: '([)'
3939
Out: false
4040
```
41+
42+
## Optimizations
43+
44+
By iteratively removing adjacent open-close pairs, you can achieve cuadratic
45+
time complexity.
46+
47+
A better approach is to iterate through the string only once, using a stack
48+
to manage the state, achieving linear time complexity.

0 commit comments

Comments
 (0)