Last active
April 24, 2019 16:02
-
-
Save pedrofaria/32dfe54ad22eb2521ca4254e0dd9c99d to your computer and use it in GitHub Desktop.
Test solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Solution1(A int, B int) string { | |
sL, sN, bL, bN := "b", B, "a", A | |
if B > A { | |
sL, sN, bL, bN = "a", A, "b", B | |
} | |
output := "" | |
f := false | |
r := 3 | |
for i := 1; i <= A+B; i++ { | |
if !f && bN == sN && i%r != 0 { | |
f = true | |
r = 2 | |
} | |
if i%r == 0 || bN == 0 { | |
output += sL | |
sN-- | |
} else { | |
output += bL | |
bN-- | |
} | |
} | |
return output | |
} | |
func Solution2(A int, B int) string { | |
sL, sN, bL, bN := "b", B, "a", A | |
if B > A { | |
sL, sN, bL, bN = "a", A, "b", B | |
} | |
bR := bN - sN | |
output := "" | |
for i := 0; i < bN; i++ { | |
if bR > 0 { | |
output += bL | |
bR-- | |
} | |
if sN > 0 { | |
output += bL + sL | |
sN-- | |
} | |
} | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment