Title: #984 - String Without AAA or BBB - LeetCode JavaScript Solutions
Open Graph Title: #984 - String Without AAA or BBB - LeetCode JavaScript Solutions
X Title: #984 - String Without AAA or BBB - LeetCode JavaScript Solutions
Description: Given two integers a and b, return any string s such that: s has length a + b and contains exactly a 'a' letters, and exactly b &...
Open Graph Description: Given two integers a and b, return any string s such that: s has length a + b and contains exactly a 'a' letters, and exactly b &...
X Description: Given two integers a and b, return any string s such that: s has length a + b and contains exactly a 'a' letters, and exactly b &...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/string-without-aaa-or-bbb
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/string-without-aaa-or-bbb","name":"#984 - String Without AAA or BBB - LeetCode JavaScript Solutions","description":"Given two integers a and b, return any string s such that: s has length a + b and contains exactly a 'a' letters, and exactly b &...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar strWithout3a3b = function(a, b) {\n let result = '';\n\n while (a > 0 || b > 0) {\n if (a > b && a > 0 && !result.endsWith('aa')) {\n result += 'a';\n a--;\n } else if (b > 0 && !result.endsWith('bb')) {\n result += 'b';\n b--;\n } else if (a > 0) {\n result += 'a';\n a--;\n } else {\n result += 'b';\n b--;\n }\n }\n\n return result;\n};","keywords":"LeetCode 984, #984 - String Without AAA or BBB, 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/string-without-aaa-or-bbb |
| 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/string-without-aaa-or-bbb/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0984-string-without-aaa-or-bbb.js |
| String | https://leetcodejavascript.com/tags/string |
| Greedy | https://leetcodejavascript.com/tags/greedy |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow