일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- python xor
- 릿코드풀기
- 상가수익률계산기
- 알고리즘풀기
- python 알고리즘
- 코틀린기초
- 파이썬 알고리즘
- binary search
- 알고리즘풀이
- 파이썬 릿코드
- python 릿코드
- 잇츠디모
- python priority queue
- python zip_longest
- 파이썬릿코드
- 파이썬 알고리즘 풀기
- 릿코드 풀기
- leetcode풀기
- 파이썬알고리즘
- 릿코드 파이썬
- leetcode풀이
- 파이썬릿코드풀기
- 릿코드
- 릿코드풀이
- leetcode 풀기
- python sorted
- LeetCode
- python Leetcode
- 파이썬알고리즘풀기
- 파이썬 프로그래머스
- Today
- Total
목록알고리즘풀이 (9)
소프트웨어에 대한 모든 것
1302. Deepest Leaves Sum https://leetcode.com/problems/deepest-leaves-sum/ Deepest Leaves Sum - LeetCode 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) hashtable을 사용해서 각 depth의 노드에 해당하는 모든 val 값들을 list 형태로 저장한다. hashtable에서 최대 depth에 O(1)로 접근해서 모든 values의 sum을 구하면 그것이 deepest lea..
380. Insert Delete GetRandom O(1) https://leetcode.com/problems/insert-delete-getrandom-o1/ Insert Delete GetRandom O(1) - LeetCode 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) hash 자료구조 사용 getRandom()은 random.choice() 사용 class RandomizedSet: def __init__(self): ''' Initializes..
155. Min Stack https://leetcode.com/problems/min-stack/ Min Stack - LeetCode 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) 두 개의 스택 활용(Normal Stack, Min Stack) Normal Stack에 요소가 추가될 때 Min Stack에는 현재의 min 요소를 추가 getMin() 호출 시 Min Stack에서 가장 상단의 요소를 리턴하면 됨. class MinStack: def __in..
771. Jewels and Stones 문제) You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". 솔루션1) class Solution: def numJewelsInStones..
226. Invert Binary Tree 문제) Given the root of a binary tree, invert the tree, and return its root. 솔루션1) # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: self.invert(root) return root def invert(se..
1684. Count the Number of Consistent Strings 문제) 솔루션1) allowed 단어에 words가 있는지 탐색 O(n2) class Solution: def countConsistentStrings(self, allowed: str, words: List[str]) -> int: # Brute-Force count = 0 for word in words: count += 1 for i in range(len(word)): if word[i] not in allowed: count -= 1 break return count 솔루션2) class Solution: def countConsistentStrings(self, allowed: str, words: List[str..
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..