Created
April 26, 2015 14:54
-
-
Save oleglukashev/12b3d0f2596b01232cbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(text) | |
result = 0 | |
text.split("").each do |item| | |
iteration_count = (item == "(") ? 1 : -1 | |
result = result + iteration_count | |
if result < 0 | |
return 0 | |
end | |
end | |
if result == 0 | |
1 | |
else | |
0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment