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(1, len(s)):
if s[i - 1].lower() != s[i].lower():
answer += 1
return answer
|
cs |
아스키코드로 비교할수도 있긴한데..
소문자로 만들어서 인접한 두 문자를 비교하는 방식이 더 쉬워 보이네요
반응형
'python-algorithm' 카테고리의 다른 글
백준 25206 너의 평점은 (0) | 2024.02.06 |
---|---|
leetcode 3028. Ant on the Boundary (0) | 2024.02.06 |
백준 9063 대지 (0) | 2024.01.24 |
leetcode 3014. Minimum Number of Pushes to Type Word I (1) | 2024.01.23 |
leetcode 3010. Divide an Array Into Subarrays With Minimum Cost I (0) | 2024.01.23 |
댓글