Python1423 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. 백준 27736 찬반투표 https://www.acmicpc.net/problem/27736 27736번: 찬반투표 투표가 통과되었으면 APPROVED, 통과되지 않았으면 REJECTED, 무효 처리되었으면 INVALID를 출력한다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 from math import ceil def sol(nums): if nums.count(0) >= ceil(len(nums)/2): return 'INVALID' elif sum(nums) 재학생절반 2.5명인데 3명으로 간주해야할 듯 싶어요 2024. 4. 21. 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. 이전 1 2 3 4 5 6 ··· 119 다음