본문 바로가기
반응형

Algorithm3

[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.
[Codility] CyclicRotation 파이썬 풀이 문제 링크: https://app.codility.com/programmers/lessons/2-arrays/ 문제 An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first plac.. 2024. 1. 23.
반응형