일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- python zip_longest
- python Leetcode
- python sorted
- leetcode풀기
- 파이썬릿코드
- 잇츠디모
- 릿코드 파이썬
- 릿코드풀이
- 알고리즘풀기
- binary search
- 상가수익률계산기
- 파이썬 알고리즘 풀기
- 알고리즘풀이
- 파이썬릿코드풀기
- LeetCode
- 파이썬 알고리즘
- 파이썬 릿코드
- python 릿코드
- 파이썬알고리즘
- 파이썬알고리즘풀기
- python priority queue
- leetcode 풀기
- python 알고리즘
- 파이썬 프로그래머스
- 코틀린기초
- 릿코드 풀기
- 릿코드풀기
- leetcode풀이
- 릿코드
- python xor
- Today
- Total
목록알고리즘 (194)
소프트웨어에 대한 모든 것
1773. Count Items Matching a Rule 문제) 솔루션1) class Solution: def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: type_dict = {} color_dict = {} name_dict ={} for item in items: if item[0] in type_dict: type_dict[item[0]] += 1 else: type_dict[item[0]] = 1 if item[1] in color_dict: color_dict[item[1]] += 1 else: color_dict[item[1]] = 1 if item[2] in name_dict: name_..
2006. Count Number of Pairs With Absolute Difference K 문제) 솔루션1) Brute-force class Solution: def countKDifference(self, nums: List[int], k: int) -> int: count = 0 for i in range(len(nums)): for j in range(i, len(nums)): if i != j and abs(nums[i] - nums[j]) == k: count += 1 return count 솔루션2) 조합 사용 class Solution: def countKDifference(self, nums: List[int], k: int) -> int: count = 0 for i, j in c..
1769. Minimum Number of Operations to Move All Balls to Each Box 문제) 솔루션1) class Solution: def minOperations(self, boxes: str) -> List[int]: res = [0] * len(boxes) for i in range(len(boxes)): for j in range(len(boxes)): if i == j: continue if boxes[j] == '1': res[i] += abs(i - j) return res 솔루션2) class Solution: def minOperations(self, boxes: str) -> List[int]: res = [0] * len(boxes) fill_idxs =..
Shuffle String 문제) 솔루션1) class Solution: def restoreString(self, s: str, indices: List[int]) -> str: res = [0] * len(s) for i1, i2 in enumerate(indices): res[i2] = s[i1] return ''.join(res) 솔루션2) class Solution: def restoreString(self, s: str, indices: List[int]) -> str: res = [0] * len(s) for idx, ch in enumerate(s): res[indices[idx]] = ch return ''.join(res)
Queries on Number of Points Inside a Circle 문제) 풀이 아이디어) 원안에 점(points)이 몇 개 있는가? 원의 중심과 점과의 거리가 r 보다 작다면 원안에 있는 것을 의미 솔루션1) class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: ret = [] for circle in queries: count_in_circle = 0 for point in points: distance = self._distance(circle, point) if distance List[int]: return [sum(self._distance_hypot(c..
Richest Customer Wealth 문제) 솔루션1) class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: max_wealth = 0 for account in accounts: max_wealth = max(max_wealth, sum(account)) return max_wealth 솔루션2) class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts))
Running Sum of 1d Array 문제) 솔루션1) class Solution: def runningSum(self, nums: List[int]) -> List[int]: ret = [nums[0]] for i in range(1, len(nums)): ret.append(ret[i-1] + nums[i]) return ret 솔루션2) from itertools import accumulate class Solution: def runningSum(self, nums: List[int]) -> List[int]: return list(accumulate(nums)) 힌트) itertools.accumulate() 함수는 누적합을 계산
Final Value of Variable After Performing Operations 문제) 솔루션1) class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: val = 0 for operation in operations: if '+' in operation: val += 1 else: val -= 1 return val 솔루션2) class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: return sum(1 if '+' in operation else -1 for operation in operations)