91. Decode Ways

    xiaoxiao2021-03-25  79

    public class Solution { public int numDecodings(String s) { if(s == null || s.length() == 0) { return 0; } if(s.length()==1) { return s.charAt(0) == '0' ?0:1; } int[] dep = new int[s.length()+1]; dep[0] = 1; dep[1] =s.charAt(0) == '0' ?0:1; for(int i = 2;i < s.length()+1;i++) { dep[i] = s.charAt(i-1) == '0' ?0:dep[i-1]; if(s.charAt(i-2)!= '0' && Integer.valueOf(s.substring(i-2,i)) <=26) { dep[i] = dep[i]+dep[i-2]; } } return dep[s.length()]; } }
    转载请注明原文地址: https://ju.6miu.com/read-20597.html

    最新回复(0)