본문 바로가기
728x90
반응형

leetcode23

Leetcode 295. Find Median (heapq 힙큐로 중간값 구하기) https://leetcode.com/problems/find-median-from-data-stream/ Find Median from Data Stream - 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 heapq는 잊을 만할때쯤 나오고 , O(NlogN)의 time complexity를 가지기 때문에 정렬에 종종 활용되는 것 같습니다. 이번 문제는 addNum의 기능에는 숫자를 추가하고 findMedian기능에서 중간값을 반환하도록 하는 문제인데요 가운데.. 2022. 11. 12.
Leetcode 212. WordSearch 2 https://leetcode.com/problems/word-search-ii/ Word Search II - 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 board라는 매트릭스에서 words에서 찾을 수 있는 단어 리스트를 반환하는 문제입니다. board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]] words = ["oath","pea","eat","rain"] Ou.. 2022. 11. 5.
Leetcode 189. Rotate Array (O(1) 제약조건) https://leetcode.com/problems/rotate-array/ Rotate Array - 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 이 문제는 간단해 보이지만 O(1)의 공간을 이용해서 풀어야 하는 문제였습니다. 즉, 별도의 공간을 할당해서 임시로 값을 저장하는 장치 같은것은 사용하지 말라는 문제였는데요 저는 처음에 deque.rotate() 를 이용해서 풀다가 nums 에 in-place로 접근해야 하는 것을 깨닫고 헤맸던 문제였습니다. R.. 2022. 10. 27.
Leetcode 310. Minimum Height Trees https://leetcode.com/problems/minimum-height-trees/ Minimum Height Trees - 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 문제를 보고 바로 전에 풀었던 Course schedule topological sort 문제가 생각났는데요 2022.09.23 - [‼ ERROR RECORD] - Leetcode 207. Course Schedule 풀이 (Topological Sorting, BFS, DFS) L.. 2022. 10. 11.
Leetcode 62. Unique Path(BFS, DP) https://leetcode.com/problems/unique-paths/ Unique Paths - 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 왼쪽 상단에서 우측하단까지 아래쪽과 오른쪽으로만 이동이 가능할 때, 고려할 수 있는 unique한 경로를 구하는 문제입니다 오랜만에 만난 matrix문제로 BFS로 풀이를 시작했습니다. class Solution: def uniquePaths(self, m: int, n: int) -> int: matrix = .. 2022. 10. 6.
Leetcode 623 . Add one Row to Tree (Binary tree) https://leetcode.com/problems/add-one-row-to-tree/ Add One Row to Tree - 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 정해진 depth 까지 도달했을 때, 주어진 val을 왼쪽과 오른쪽 노드로 삽입하고 기존의 왼쪽 노드는 새로운 노드의 왼쪽, 기존의 오른쪽 노드는 새로운 노드의 오른쪽으로 재배열 하는 문제입니다. 제가 처음에 접근했던 방식은 BFS로 stack을 통해 아래 로직을 전개하는걸로 생각했습니다.. 2022. 10. 5.
728x90
반응형