Decode Ways
A message made of capital letters is encoded as digits using A = 1, B = 2, ..., Z = 26. The digits are written one after another with no separators, so the same digit string can often be split into letters in more than one way. For example "11106" can be read as 1 1 10 6 or 11 10 6.
Given a string s of digits, return the number of different ways to decode it. Codes do not have leading zeros: "06" is not 6, and a lone 0 is not a letter. If no decoding exists, return 0.
Constraints
1 <= s.length <= 100scontains only digits and may start with0.- The answer fits in a 32-bit integer.
Examples
Example 1
Input: s = "12" Output: 2
It can be read as 1, 2 ("AB") or as 12 ("L"): two ways.
Example 2
Input: s = "226" Output: 3
2 2 6, 22 6 and 2 26 are all valid: three ways.
Example 3
Input: s = "06" Output: 0
A leading 0 cannot be decoded, and "06" is not allowed as a two-digit code: zero ways.
JavaScript you'll use: Strings and characters Numbers, Math and integer tricks
/**
* @param {string} s
* @return {number}
*/
function numDecodings(s) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.