#984

String Without AAA or BBB

specialist · 980 · lc medium +32 · failed · 45% accepted · 872 likes · top 28%

Description

Build any string that uses exactly a copies of 'a' and b copies of 'b' without ever containing the three-character run "aaa" or "bbb" as a substring.

Example 1:

Input: a = 1, b = 2
Output: "abb"
Explanation: "abb", "bab" and "bba" are all correct answers.

Example 2:

Input: a = 4, b = 1
Output: "aabaa"

Code

1
2
3