We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65865d7 commit 35fd428Copy full SHA for 35fd428
src/easy/valid_parentheses.rs
@@ -26,7 +26,18 @@ pub fn is_valid(s: String) -> bool {
26
}
27
28
/*
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
41
*/
42
43
#[test]
0 commit comments