Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created July 10, 2019 03:13
Show Gist options
  • Save jubishop/856cb68dd13211501b2052ec05a50cc3 to your computer and use it in GitHub Desktop.
Save jubishop/856cb68dd13211501b2052ec05a50cc3 to your computer and use it in GitHub Desktop.
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