Skip to content

Instantly share code, notes, and snippets.

@mirjoy
mirjoy / well_formed_string
Created May 26, 2015 22:01
well formed string
class StringForm
def valid_string?(str)
string_array = str.chars
new_array = []
string_array.length.times do
if ["[", "{", "("].include?(string_array.first)
new_array << string_array.shift
elsif ["]", "}", ")"].index(string_array.first) == ["[", "{", "("].index(new_array.last)
string_array.shift && new_array.pop