Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. class Solution:
  2.     def longestDiverseString(self, a: int, b: int, c: int) -> str:
  3.         c = min((a + b + 1) * 2, c)
  4.         b = min((c + a + 1) * 2, b)
  5.         a = min((c + b + 1) * 2, a)
  6.         cand = sorted([(a, 'a'),(b, 'b'),(c,'c')])
  7.         bestCount, bestChar = cand.pop()
  8.         chunks = [bestChar * 2] * (bestCount // 2)
  9.         if bestCount % 2 == 1:
  10.             chunks.append(bestChar)
  11.        
  12.         index = 0
  13.         for count, char in cand:
  14.             for i in range(count):
  15.                 chunks[index] += char
  16.                 index = (index + 1) % len(chunks)
  17.                
  18.         return ''.join(chunks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement