2405. Optimal Partition of String

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2405

class Solution:
    def partitionString(self, s: str) -> int:
        res, v = 1, 0
        for c in s:
            i = ord(c) - ord('a')
            if (v >> i) & 1:
                v = 0
                res += 1
            v |= 1 << i
        return res