using System; using System.Collections.Generic; using System.Linq; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 解码 * @param nums string字符串 数字串 * @return int整型 */ public int solve (string nums) { if(nums == "0") return 0; int res = 1; int[] pre = new int[2]; pre[0] = 1; pre[1] = 1; for(int i = 1; i < nums.Length; i++){ if(nums[i] == '0' && (nums[i-1] - '0' > 2 || nums[i-1] == '0')){ return 0; } if(nums[i] != '0' && (nums[i] - '0' <= 6 && nums[i - 1] == '2' || nums[i - 1] == '1') ){ Console.WriteLine("pre:" + pre[i % 2]); res = res + pre[i % 2]; } Console.WriteLine(res); pre[i % 2] = res; } return res; } }