Created
September 11, 2016 07:17
-
-
Save danielpowell4/03033eb6f098d7d2edd59d4130861f8e to your computer and use it in GitHub Desktop.
Checks if parens are valid returning true or false
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_parentheses(string) | |
open = 0 | |
string.chars.each do |c| | |
open += 1 if c == "(" | |
open -= 1 if c == ")" | |
return false if open < 0 | |
end | |
open == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment