---
# System prepended metadata

title: 0091. Decode Ways
tags: [Leetcode, Dynamic Programming, Medium]

---

# 0091. Decode Ways
###### tags: `Leetcode` `Medium` `Dynamic Programming`
Link： https://leetcode.com/problems/decode-ways/

## 思路

## Java Code
```java=
class Solution {
    public int numDecodings(String s) {
        int str_len = s.length();
        int dp[] = new int[str_len+1];
        dp[0] = 1;
        for(int i = 1;i <= str_len;i++){
            if(s.charAt(i-1) != '0'){
                dp[i]+=dp[i-1];
            }
            
            if(i>1 && s.charAt(i-2)!='0'&&(s.charAt(i-2)-'0')*10+(s.charAt(i-1)-'0')<=26){
                dp[i]+=dp[i-2];
            }
        }
        return dp[str_len];
    }
}
```
## Result
Runtime: 1 ms, faster than **93.62%** of Java online submissions for Decode Ways.
Memory Usage: 37 MB, less than **93.07%** of Java online submissions for Decode Ways.
