Created
July 10, 2019 03:13
-
-
Save jubishop/856cb68dd13211501b2052ec05a50cc3 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 num_search(string, ans) | |
if (string.empty?) | |
ans[:count] += 1 | |
return | |
end | |
return if string[0] == "0" | |
num_search(string[1..-1], ans) | |
if (string.length > 1 and (string[0].to_i < 2 or (string[0].to_i == 2 and string[1].to_i < 7))) | |
num_search(string[2..-1], ans) | |
end | |
end | |
def num_decodings(string) | |
return 0 if string.empty? or string[0] == "0" | |
ans = {:count => 0} | |
num_search(string, ans) | |
return ans[:count] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment