From 8cd982815b135dd3969227d0393e96daf178871e Mon Sep 17 00:00:00 2001 From: sourcema Date: Thu, 28 Mar 2019 21:42:16 +0800 Subject: [PATCH] Create sourcema.md --- 2019.02.09-leetcode91/sourcema.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 2019.02.09-leetcode91/sourcema.md diff --git a/2019.02.09-leetcode91/sourcema.md b/2019.02.09-leetcode91/sourcema.md new file mode 100644 index 000000000..15305a2f7 --- /dev/null +++ b/2019.02.09-leetcode91/sourcema.md @@ -0,0 +1,26 @@ +# LeetCode 91 + class Solution { + public int numDecodings(String s) { + if (s.length() == 0||s.charAt(0)=='0') { + return 0; + } + return find(s,0); + } + private int find(String s,int index) { + if (index == s.length()) { + return 1; + } + if (s.charAt(index) == '0') { + return 0; + } + int res=0; + res += find(s, index + 1); + if (index + 1 < s.length() && s.charAt(index) == '1') { + res += find(s,index+ 2); + } + if (index + 1 < s.length() && (s.charAt(index) == '2')&&s.charAt(index+1)<='6') { + res += find(s,index + 2); + } + return res; + } +}