481 Magical String Description link Solution See Code Code class Solution: def magicalString(self, n: int) -> int: S = [1,2,2] idx = 2 while len(S) < n: S += S[idx] * [(3 - S[-1])] idx += 1 return S[:n].count(1)