Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 386 Bytes

481.md

File metadata and controls

28 lines (19 loc) · 386 Bytes

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)