Title: #91 - Decode Ways - LeetCode JavaScript Solutions
Open Graph Title: #91 - Decode Ways - LeetCode JavaScript Solutions
X Title: #91 - Decode Ways - LeetCode JavaScript Solutions
Description: You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> ...
Open Graph Description: You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> ...
X Description: You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/decode-ways
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/decode-ways","name":"#91 - Decode Ways - LeetCode JavaScript Solutions","description":"You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s\n * @return {number}\n */\nvar numDecodings = function(s) {\n if (s == null || s.length === 0) return 0;\n if (s[0] === '0') return 0;\n\n const group = new Array(s.length + 1).fill(0);\n group[0] = 1;\n group[1] = 1;\n\n for (let i = 2; i <= s.length; i++) {\n const a = Number(s.slice(i - 1, i));\n if (a >= 1 && a <= 9) {\n group[i] += group[i - 1];\n }\n\n const b = Number(s.slice(i - 2, i));\n if (b >= 10 && b <= 26) {\n group[i] += group[i - 2];\n }\n }\n\n return group[s.length];\n};","keywords":"LeetCode 91, #91 - Decode Ways, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/decode-ways |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/decode-ways/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0091-decode-ways.js |
| String | https://leetcodejavascript.com/tags/string |
| Dynamic Programming | https://leetcodejavascript.com/tags/dynamic-programming |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow