본문 바로가기

LeetCode340

leetcode 3074. Apple Redistribution into Boxes https://leetcode.com/problems/apple-redistribution-into-boxes/description/ 12345678class Solution:    def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int:        total_apple = sum(apple)        capacity.sort(reverse = True)        for i in range(len(capacity)):            if sum(capacity[:i+1]) >= total_apple:                return i + 1        Colored by Color Scriptercs 2024. 4. 25.
leetcode 1137. N-th Tribonacci Number https://leetcode.com/problems/n-th-tribonacci-number/description/?envType=daily-question&envId=2024-04-24 123456class Solution:    def tribonacci(self, n: int) -> int:        answer = [0, 1, 1]        for i in range(2, n):            answer.append(answer[i] + answer[i - 1] + answer[i - 2])        return answer[n]Colored by Color Scriptercs 2024. 4. 25.
leetcode 3065. Minimum Operations to Exceed Threshold Value I https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i/description/ 12345class Solution: def minOperations(self, nums: List[int], k: int) -> int: answer = [1 if num 2024. 4. 24.
leetcode 3069. Distribute Elements Into Two Arrays I https://leetcode.com/problems/distribute-elements-into-two-arrays-i/description/ 1 2 3 4 5 6 7 8 9 10 11 class Solution: def resultArray(self, nums: List[int]) -> List[int]: arr1 = [nums[0]] arr2 = [nums[1]] for i in range(2, len(nums)): if arr1[-1] > arr2[-1]: arr1.append(nums[i]) elif arr1[-1] 2024. 4. 24.
leetcode 3079. Find the Sum of Encrypted Integers https://leetcode.com/problems/find-the-sum-of-encrypted-integers/description/ 12345678910class Solution: def sumOfEncryptedInt(self, nums: List[int]) -> int: answer = 0 for num in nums: str_num = str(num) max_digit = str(max(map(int, list(str_num)))) tmp_answer = int(max_digit * len(str_num)) answer += tmp_answer return answer Colored by Color Scriptercs 2024. 4. 24.
leetcode 3083. Existence of a Substring in a String and Its Reverse https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/description/ 12345678class Solution: def isSubstringPresent(self, s: str) -> bool: reverse_s = s[::-1] for i in range(1, len(s)): if reverse_s[i-1:i+1] in s: return True return Falsecs 2024. 4. 24.
leetcode 3099. Harshad Number https://leetcode.com/problems/harshad-number/description/ 12345678class Solution: def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int: new_number = sum(list(map(int, list(str(x))))) if x % new_number == 0: return new_number else: return -1 Colored by Color Scriptercs 2024. 4. 23.
leetcode 3046. Split the Array https://leetcode.com/problems/split-the-array/description/ 12345678class Solution: def isPossibleToSplit(self, nums: List[int]) -> bool: set_nums = list(set(nums)) for num in set_nums: if nums.count(num) >= 3: return False return TrueColored by Color Scriptercs 2024. 4. 22.
leetcode 3110. Score of a String https://leetcode.com/problems/score-of-a-string/description/ 1234567class Solution: def scoreOfString(self, s: str) -> int: answer = 0 for i in range(1, len(s)): answer += abs(ord(s[i]) - ord(s[i-1])) return answercs 2024. 4. 22.
leetcode 3120. Count the Number of Special Characters I https://leetcode.com/problems/count-the-number-of-special-characters-i/description/ 1 2 3 4 5 6 7 8 class Solution: def numberOfSpecialChars(self, word: str) -> int: answer = 0 for i in range(26): if chr(i + 97) in word and chr(i + 97).upper() in word: answer += 1 return answer Colored by Color Scripter cs 2024. 4. 21.
leetcode 3038. Maximum Number of Operations With the Same Score I https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/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 10 11 class Solution: def maxOperations(self, nums: List[int]) .. 2024. 2. 18.
leetcode 1941. Check if All Characters Have Equal Number of Occurrences https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/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 areOccurrencesEqual(self, s: str) -> .. 2024. 2. 17.