반응형 leetcode2 [LeetCode] Number of Changing Keys https://leetcode.com/problems/number-of-changing-keys/ int: s = s.lower() answer = 0 # 처음 문자를 가지고 origin = s[0] # 두번째 문자부터 for i in s[1:]: if i!=origin: answer += 1 origin = i return answer cs 제출 결과 속도가 느린편에 속한데, 빠른 사람들의 코드를 보면 크게 로직의 차이는 없다. 제일 빠른 사람의 코드이다. 1 2 3 4 5 6 7 8 9 class Solution: def countKeyChanges(self, s: str) -> int: s = s.lower() count = 0 for i in range(1,len(s)): if s[i] != s[.. 2024. 2. 24. [LeetCode] 3042. Count Prefix and Suffix Pairs https://leetcode.com/problems/count-prefix-and-suffix-pairs-i Count Prefix and Suffix Pairs I - LeetCodeCan you solve this real interview question? Count Prefix and Suffix Pairs I - You are given a 0-indexed string array words. Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2: * isPrefixAndSuffix(str1, str2) returns truleetcode.com 주어진 string 리스트에서 하나의 단어가 .. 2024. 2. 23. 이전 1 다음 반응형