일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 재택근무
- clean code
- 코딩
- 프로그래머스
- PrivateRouter
- 클린 코드
- 취미
- Kriss 재택
- Python
- 그림
- 프로그래밍
- 테스팅 자격증
- 색연필
- KSTQB
- 토익 환급
- 연필
- 웹개발
- leetcode
- 코딩테스트
- csts
- IT자격증
- 소묘
- 다비드상
- 미켈란젤로
- 연필소묘
- 코드잇
- 알고리즘
- 파이썬
- IT 자격증
- react
- Today
- Total
목록알고리즘/Leetcode (6)
글모음
굳이 왜 original tree랑 cloned tree 두개를 주는지 이해가 가지 않는다. 그냥 original tree를 주고 target 숫자를 탐색하라고 하면 되는거 아닌가?.. Find a Corresponding Node of a Binary Tree in a Clone of That 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

기준점 상하좌우 탐색해서 같다면 newColor 값으로 바꿔주는 DFS 문제 [ 코드 1. 실패 ] def floodFill(self, image, sr, sc, newColor): limit_x = list(range(len(image)+1)) limit_y = list(range(len(image[0]))) l_color = image[sr][sc] def dfs(x, y): positions = [[x, y-1], [x, y+1], [x-1, y], [x+1, y]] if x in limit_x and y in limit_y: if image[x][y] == l_color: image[x][y] = newColor for i in range(len(positions)): if positions[i]..

[ 문제 풀이 ] Preorder는 DFS(Depth First Search) 탐색 방법 중 하나이고, DFS는 스택으로 주로 구현한다. Preorder는 3가지의 단계로 탐색을 한다. 1. Visit the Node 2. Traverse left 3. Traverse right [ Root -> Left -> right ] [ 루트 -> 왼쪽 노드 -> 오른쪽 노드 ] 순으로 순회를 한다. 한국어로 Preorder는 전위 순회, 이때 전은 먼저라는 뜻의 '前' 한글로 보면 바로 뭔지 체감이 안 가고 영어 단어를 보면 바로 이해가 간다. 영어로는 Preorder인데 Pre-order인 이유는 먼저 노드 방문부터 하고 그다음에 왼쪽, 오른쪽 탐색을 하기 때문 탐색보다 노드 방문을 먼저로 하기 때문이다. <..

1부터 n까지의 숫자들을 list에 넣고, 넣을 때 "Push" 만약 target에 해당하는 숫자가 없다면 제거하면서 "Pop" 기초적인 stack 문제다. [ 코드 1 ] class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: ans, temp = [], [] for i in range(1,n+1): temp.append(i) ans.append("Push") if i not in target: temp.pop() ans.append("Pop") if temp == target: break return ans Push, Pop을 넣어줄 정답 리스트 ans 굳이 추가로 list를 만들어주지 않아도 괜찮지만 숫자들이 Pus..

[ 정답 1 ] 카테고리: 스택 Runtime: 35.97% Memory Usage: 48.21% 시간 복잡도 : O(n) - for문 하나 공간 복잡도 : O(n) - list 하나 class Solution: def calPoints(self, ops): record = [] for i in range(len(ops)): try: record.append(int(ops[i])) except: if ops[i] == "C": record.pop() elif ops[i] == "D": record.append(2* record[-1]) elif ops[i] == "+": record.append(record[-2] + record[-1]) return sum(record) 1. 값들을 저장할 list 하..
682. Baseball Game