본문 바로가기

LeetCode342

leetcode 3330. Find the Original Typed String I https://leetcode.com/problems/find-the-original-typed-string-i/description/ 1234567891011class Solution:    def possibleStringCount(self, word: str) -> int:        answer = 1        current_alphabet = word[0]        for i in range(1, len(word)):            if word[i] == word[i - 1]:                answer += 1                            else:                                current_alphabet = word.. 2024. 10. 27.
3300. Minimum Element After Replacement With Digit Sum https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum/123456class Solution:    def minElement(self, nums: List[int]) -> int:                answer = [sum(map(int, str(nums[i]))) for i in range(len(nums))]         return min(answer)Colored by Color Scriptercslist comprehension과 각 자리수 합을 구하기 위해서원본 데이터 타입을 문자열로 타입 캐스팅해서 사용합니다. 2024. 10. 5.
leetcode 3210. Find the Encrypted String https://leetcode.com/problems/find-the-encrypted-string/description/12345678class Solution:    def getEncryptedString(self, s: str, k: int) -> str:        answer = ""         for i in range(len(s)):            answer += s[(i+k)%len(s)]                return answerColored by Color Scriptercs문자열 s 를 rotate 하는 느낌으로 구현 2024. 9. 23.
3194. Minimum Average of Smallest and Largest Elements https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements/description/12345678910class Solution:    def minimumAverage(self, nums: List[int]) -> float:        nums.sort()        averages = []        for i in range(len(nums)//2):            averages.append((nums[i] + nums[-(i+1)])/2)                return min(averages)         Colored by Color Scriptercs 2024. 9. 21.
3232. Find if Digit Game Can Be Won https://leetcode.com/problems/find-if-digit-game-can-be-won/description/ 1234567891011121314class Solution:    def canAliceWin(self, nums: List[int]) -> bool:        sum_single, sum_double = 0, 0        for num in nums:            if num  10 :                sum_single += num            else:                sum_double += num         if sum_single == sum_double:            return False        els.. 2024. 9. 21.
3285. Find Indices of Stable Mountains https://leetcode.com/problems/find-indices-of-stable-mountains/description/ 12345678class Solution:    def stableMountains(self, height: List[int], threshold: int) -> List[int]:        answer = []        for i in range(1, len(height)):            if height[i - 1] > threshold:                answer.append(i)                return answerColored by Color Scriptercsheight 리스트를 순차 탐색하면서 바로 직전 값이 thre.. 2024. 9. 21.
3190. Find Minimum Operations to Make All Elements Divisible by Three https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three/description/ 123456789class Solution:    def minimumOperations(self, nums: List[int]) -> int:        answer = 0        for num in nums:            if num % 3 != 0:                answer += 1                return answer        Colored by Color Scriptercscase 1 ) 숫자가 3으로 나눴을때 나머지 가 0 인 경우  : 아무것도 안해도됨cas.. 2024. 9. 19.
leetcode 3280. Convert Date to Binary https://leetcode.com/problems/convert-date-to-binary/description/12345class Solution:    def convertDateToBinary(self, date: str) -> str:        yyyy, mm, dd = map(int, date.split("-"))         return bin(yyyy)[2:]+"-"+bin(mm)[2:]+"-"+bin(dd)[2:]cspython 내장함수 bin을 통해 구현 2024. 9. 12.
leetcode 1684. Count the Number of Consistent Strings https://leetcode.com/problems/count-the-number-of-consistent-strings/description/?envType=daily-question&envId=2024-09-12 12345678910class Solution:    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:        answer = 0        allowed_set = set(list(allowed))        for word in words:            word_set = set(list(word))            if word_set.issubset(allowed_set) :     .. 2024. 9. 12.
leetcode 3270. Find the Key of the Numbers https://leetcode.com/problems/find-the-key-of-the-numbers/description/ 1234567891011121314class Solution:    def generateKey(self, num1: int, num2: int, num3: int) -> int:        str_num1, str_num2, str_num3 = str(num1), str(num2), str(num3)        max_length = max(len(str_num1), len(str_num2), len(str_num3))         str_num1 = str_num1.zfill(max_length)        str_num2 = str_num2.zfill(max_leng.. 2024. 9. 2.
leetcode 2000. Reverse Prefix of Word https://leetcode.com/problems/reverse-prefix-of-word/description 1234567class Solution:    def reversePrefix(self, word: str, ch: str) -> str:        if word.find(ch) == -1:            return word        else:            return word[:word.find(ch)+1][::-1] + word[word.find(ch)+1:]        Colored by Color Scriptercs 2024. 5. 2.
leetcode 3131. Find the Integer Added to Array I https://leetcode.com/problems/find-the-integer-added-to-array-i/description/ 123456class Solution:    def addedInteger(self, nums1: List[int], nums2: List[int]) -> int:        nums1.sort()        nums2.sort()        return nums2[0] - nums1[0]        Colored by Color Scriptercs 2024. 4. 30.