Skip to content

Instantly share code, notes, and snippets.

@danielrose7
Created September 11, 2016 07:17
Show Gist options
  • Save danielrose7/03033eb6f098d7d2edd59d4130861f8e to your computer and use it in GitHub Desktop.
Save danielrose7/03033eb6f098d7d2edd59d4130861f8e to your computer and use it in GitHub Desktop.
Checks if parens are valid returning true or false
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