[LeetCode] 1529. Minimum Suffix Flips

김민우·2022년 12월 11일
0

알고리즘

목록 보기
83/189

- Problem

1529. Minimum Suffix Flips

- 내 풀이

class Solution:
    def minFlips(self, target: str) -> int:
        answer = 0

        for i in range(len(target) - 1):
            if target[i+1] != target[i]:
                answer += 1
        
        return answer + (target[0] == '1')

- Short Coding

class Solution:
    def minFlips(self, target: str) -> int:
        return sum(target[i] != target[i+1] for i in range(len(target) - 1)) + (target[0] == "1")

- 결과

profile
Pay it forward.

0개의 댓글