Created
November 12, 2013 03:49
-
-
Save prat0318/7425181 to your computer and use it in GitHub Desktop.
encode strings A->1...Z->26 ...total combinations possible by reading input string
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 encoding_ways(str): | |
if((len(str) == 1) or (len(str) == 0)): return 1 | |
total1 = encoding_ways(str[1:]) | |
if((str[0] == '1') or ((str[0] == '2') and (1 <= int(str[1])) and (int(str[1]) <= 6))): | |
total1 = total1 + encoding_ways(str[2:]) | |
return total1 | |
print encoding_ways('12') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment