Decode Ways
来源:互联网 发布:菜鸟商城源码 编辑:程序博客网 时间:2024/06/03 22:40
public class Solution { public int numDecodings(String s) { if (s == null || s.length() == 0) { return 0; } //int[] nums = new int[s.length() + 1]; //nums[0] = 1; //nums[1] = s.charAt(0) != '0' ? 1 : 0; int first = 1; int second = s.charAt(0) != '0' ? 1: 0; if (s.length() == 1) { return second; } int third = 0; for (int i = 2; i <= s.length(); i++) { third = 0; if (s.charAt(i - 1) != '0') { //nums[i] = nums[i - 1]; third = second; } int sum = (s.charAt(i - 2) - '0') * 10 + (s.charAt(i - 1) - '0'); if (sum >= 10 && sum <= 26) { //nums[i] += nums[i - 2]; third += first; } first = second; second = third; } return third; }}
0 0
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- 在c++程序中调用被c编译器编译后的函数为什么要加extern “C”
- LIS 最长上升子序列问题 nlgn时间打印其中一个序列
- SOA与云计算--竞争还是融合
- HDU 1269-迷宫城堡(强连通分量)
- Decode Ways
- blog.fidroid.com
- 数据持久化--沙盒
- linux下一些问题
- picasso vs UIL
- 制作Opencontrail的发布包
- js获取浏览器类型(包含IE11)
- Codeforces 551C - GukiZ hates Boxes (二分 + 贪心)
- C++标准库中sstream与strstream的区别详细解析