본문 바로가기

2024/0430

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.
leetcode 1266. Minimum Time Visiting All Points https://leetcode.com/problems/minimum-time-visiting-all-points/ 12345678910111213141516171819202122232425262728293031323334353637383940414243class Solution:    def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:        def sol(point1, point2):            cost = 0             def move1():                nonlocal cost                while point1[0] != point2[0] and point1[1] != poin.. 2024. 4. 27.
leetcode 2855. Minimum Right Shifts to Sort the Array https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array/description/ 123456789class Solution:    def minimumRightShifts(self, nums: List[int]) -> int:        sorted_nums = sorted(nums)        for i in range(len(nums)):            if nums == sorted_nums:                return i            nums = nums[-1: -2: -1] + nums[:len(nums)-1]                return -1Colored by Color Scriptercs 2024. 4. 26.
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.