IT/코딩테스트 (111) 썸네일형 리스트형 [Leetcode] 3079. Find the Sum of Encrypted Integers https://leetcode.com/problems/find-the-sum-of-encrypted-integers/ class Solution: def sumOfEncryptedInt(self, nums: List[int]) -> int: encrypted_nums = [] for n in nums: ndigit = list(map(int, str(n))) if len(ndigit) > 1: max = -1 for i in ndigit: if max < i: max = i encrypted = int(str(max) * len(ndigit)) encrypted_nums.append(encrypted) else: encrypted_nums.append(n) sum = 0 for n in encrypted.. [Leetcode] 525. Contiguous Array https://leetcode.com/problems/contiguous-array class Solution: def findMaxLength(self, nums: List[int]) -> int: length = 0 count = 0 count_map = {0: -1} for i in range(len(nums)): if nums[i] == 0: count -= 1 else: count += 1 if count in count_map: length = max(length, i - count_map[count]) else: count_map[count] = i return length [Leetcode] 238. Product of Array Except Self https://leetcode.com/problems/product-of-array-except-self class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: result = [1] * len(nums) prifix_value = 1 for i in range(0, len(nums)): result[i] *= prifix_value prifix_value *= nums[i] suffix_value = 1 for i in range(len(nums)-1, -1, -1): result[i] *= suffix_value suffix_value *= nums[i] return result [Leetcode] 930. Binary Subarrays With Sum https://leetcode.com/problems/binary-subarrays-with-sum class Solution: def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: count = 0 prifix = {0:1} sum = 0 for i in nums: sum += i count += prifix.get(sum - goal, 0) prifix[sum] = prifix.get(sum, 0) + 1 return count [Leetcode] 2485. Find the Pivot Integer https://leetcode.com/problems/find-the-pivot-integer class Solution: def pivotInteger(self, n: int) -> int: for x in range(n + 1): sum1 = 0 sum2 = 0 for i in range(1, x + 1): sum1 += i for i in range(x, n + 1): sum2 += i if sum1 == sum2: return x return -1 [Leetcode] 791. Custom Sort String https://leetcode.com/problems/custom-sort-string class Solution: def customSortString(self, order: str, s: str) -> str: result = '' for i in order: for j in range(s.count(i)): result += i s = s.replace(i, '') result += s return result [Leetcode] 3074. Apple Redistribution into Boxes https://leetcode.com/problems/apple-redistribution-into-boxes class Solution: def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int: sum = 0 for n in apple: sum += n print('sum: ' + str(sum)) capacity.sort(reverse=True) c_sum = 0 for i in range(len(capacity)): c_sum += capacity[i] if c_sum >= sum: break return i + 1 [Leetcode] 349. Intersection of Two Arrays https://leetcode.com/problems/intersection-of-two-arrays class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: return list(set(nums1).intersection(nums2)) 이전 1 2 3 4 5 6 7 ··· 14 다음