Title: #1417 - Reformat The String - LeetCode JavaScript Solutions
Open Graph Title: #1417 - Reformat The String - LeetCode JavaScript Solutions
X Title: #1417 - Reformat The String - LeetCode JavaScript Solutions
Description: You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to fi...
Open Graph Description: You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to fi...
X Description: You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to fi...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/reformat-the-string
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/reformat-the-string","name":"#1417 - Reformat The String - LeetCode JavaScript Solutions","description":"You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to fi...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n const letters = [];\n const digits = [];\n for (const char of s) {\n if (isNaN(char)) {\n letters.push(char);\n } else {\n digits.push(char);\n }\n }\n if (Math.abs(letters.length - digits.length) > 1) {\n return '';\n }\n const result = [];\n const longer = letters.length >= digits.length ? letters : digits;\n const shorter = longer === letters ? digits : letters;\n for (let i = 0; i < longer.length; i++) {\n result.push(longer[i]);\n if (i < shorter.length) {\n result.push(shorter[i]);\n }\n }\n return result.join('');\n};","keywords":"LeetCode 1417, #1417 - Reformat The String, Easy, 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/reformat-the-string |
| 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/reformat-the-string/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1417-reformat-the-string.js |
| String | https://leetcodejavascript.com/tags/string |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow