Skip to content

Instantly share code, notes, and snippets.

@kermit-klein
Created October 17, 2020 20:10
Show Gist options
  • Save kermit-klein/c7856371110f56f7db61037a59996a5c to your computer and use it in GitHub Desktop.
Save kermit-klein/c7856371110f56f7db61037a59996a5c to your computer and use it in GitHub Desktop.
gemfunc
module CheckParans
def self.valid_parentheses(string)
only_parants = string.scan(/([()])/)
if only_parants.empty?
true
elsif only_parants.length == 1
false
end
k = false
until k == true
dummy = only_parants.length
(0..only_parants.length - 1).each do |i|
next unless only_parants[i] == ['('] && only_parants[i + 1] == [')']
only_parants.delete_at(i)
only_parants.delete_at(i)
break
end
k = true if dummy == only_parants.length
end
only_parants.empty? ? true : false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment