Skip to content

Instantly share code, notes, and snippets.

@danielpowell4
Created September 11, 2016 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpowell4/03033eb6f098d7d2edd59d4130861f8e to your computer and use it in GitHub Desktop.
Save danielpowell4/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