Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestDiverseString(self, a: int, b: int, c: int) -> str:
- c = min((a + b + 1) * 2, c)
- b = min((c + a + 1) * 2, b)
- a = min((c + b + 1) * 2, a)
- cand = sorted([(a, 'a'),(b, 'b'),(c,'c')])
- bestCount, bestChar = cand.pop()
- chunks = [bestChar * 2] * (bestCount // 2)
- if bestCount % 2 == 1:
- chunks.append(bestChar)
- index = 0
- for count, char in cand:
- for i in range(count):
- chunks[index] += char
- index = (index + 1) % len(chunks)
- return ''.join(chunks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement