Skip to content

Instantly share code, notes, and snippets.

@Bablzz
Created July 25, 2017 19:11
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 Bablzz/c0c207cf9eeb04121b59080082221470 to your computer and use it in GitHub Desktop.
Save Bablzz/c0c207cf9eeb04121b59080082221470 to your computer and use it in GitHub Desktop.
def check(arr)
counter = 0
arr.each do |key|
if key == '('
counter += 1
else
counter -= 1
end
end
if (counter < 0 || counter > 0)
return false
else
return true
end
end
seq = '(()())'.split('')
puts check(seq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment