Skip to content

Commit 35fd428

Browse files
committed
docs: add algoritm description in valid parentheses using a stack
1 parent 65865d7 commit 35fd428

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/easy/valid_parentheses.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ pub fn is_valid(s: String) -> bool {
2626
}
2727

2828
/*
29-
29+
Algorithm: Using a stack
30+
- Create a stack
31+
- Iterate through the string
32+
- If the character is an opening bracket, push it onto the stack
33+
- If the character is a closing bracket, pop the stack and compare the popped character with the current character
34+
- If the popped character is not the corresponding opening bracket, return false
35+
- If the stack is empty, return true
36+
- Else, return false
37+
38+
Time: O(n)
39+
Space: O(n)
40+
3041
*/
3142

3243
#[test]

0 commit comments

Comments
 (0)