# Decode Ways

## Jump 1 or 2 steps, Climbing Stairs

"12", it could be decoded as "AB" (1 2) or "L" (12).

It is just like jumping 1 step A B or 2 steps 12.

But, there are some restrictions.

e.g.

"31" can only decode as "C" (3) and "A" (1)

So, what we need to do is to add something to the `Climbing Stairs`

, do not climb the invalid stairs.

### Source code *Read on Github*

```
1 public class Solution {
2
3 public int numDecodings(String s) {
4 // IMPORTANT: Please reset any member data you declared, as
5 // the same Solution instance will be reused for each test case.
6
7 final char[] _s = s.toCharArray();
8 final int n = _s.length;
9
10 if (n == 0 ) return 0;
11
12 int[] step = new int[Math.max(n + 1, 3)];
13
14 step[0] = 1;
15
16 step[1] = 0;
17
18 if(_s[0] != '0')
19 step[1] = 1;
20
21 for(int i = 2; i <= n; i++){
22
23 step[i] = 0;
24
25 if ( _s[i - 1] != '0' ){
26 step[i] += step[i - 1];
27 }
28
29 if ( _s[i - 2] != '0' ){
30 if ( (_s[i - 2] - '0') * 10 + (_s[i - 1] - '0') <= 26 )
31 step[i] += step[i - 2];
32 }
33
34 }
35
36 return step[n];
37 }
38
39 }
```