본문 바로가기
python-algorithm

leetcode 3019. Number of Changing Keys

by 무적김두칠 2024. 2. 5.

https://leetcode.com/problems/number-of-changing-keys/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

1
2
3
4
5
6
7
8
9
class Solution:
    def countKeyChanges(self, s: str-> int:
        answer = 0
        for i in range(1len(s)):
            if s[i - 1].lower() != s[i].lower():
                answer += 1
        
        return answer
        
cs

아스키코드로 비교할수도 있긴한데.. 

소문자로 만들어서 인접한 두 문자를 비교하는 방식이 더 쉬워 보이네요

반응형

댓글