题解 | #把数字翻译成字符串#
把数字翻译成字符串
https://www.nowcoder.com/practice/046a55e6cd274cffb88fc32dba695668
import java.util.*; public class Solution { /** * 解码 * @param nums string字符串 数字串 * @return int整型 */ public int solve(String nums) { // write code here int len = nums.length(); if (len <= 0) { return 0; } if (nums.contains("00")) { return 0; } return check(nums, 0, len); } public int check(String s, int i, int len) { if (i >= len) { return 1; } if (s.charAt(i) == '0') { return 0; } int num = Integer.parseInt(s.substring(i, i + 1)); if (num >= 3) { return check(s, i + 1, len); } else { if(i+1<len){ int num2 = Integer.parseInt(s.substring(i, i + 2)); if(num2<=26){ return check(s, i + 1, len) + check(s, i + 2, len); }else{ return check(s,i+1,len); } }else{ return check(s, i + 1, len); } } } }