Binary Search Tree의 root node와 Target value가 주어지고, Tree의 모든 node를 탐색해 Target value의 가장 근사한 value를 가진 node를 return하면 된다. DFS를 통해 left child와 right child가 존재하면 계속 탐색해 나가는 방식으로 구현했다. class Solution: def closestValue(self, root: Optional[TreeNode], target: float) -> int: def dfs(node, target): l = r = math.inf if node.left != None: l = abs(node.left.val - target) if node.right != None: r = abs(node...
Relational keys : We need to be able to identify one or more attributes that uniquely identifies each tuple in a relation. : 우리는 relation(관계) 속에서 각 튜플(row)를 고유하게 인식 또는 분간해주는 하나 또는 여러개의 속성이 필요한데 이를 relational keys라고 한다. Relational key의 종류는 아래와 같다. 1. Super Key(슈퍼키) : An attribute, or set of attributes, that uniquely identifies a tuple within a relation. : 하나 또는 여러 속성의 집합으로 각 튜플을 고유하게 구분해준다. 즉, Su..
전형적인 Union-Find를 활용하는 문제다. 다만 Cycle이 발생할 수 있기에 이 때(if px == py) false를 반환하는 조건만 추가해주고 Parent가 하나라도 다르다면 Tree가 두 개 이상 생기는 것이기에 false를 반환하면 된다. class Solution: def find(self, p, x): if p[x] == x: return x return self.find(p, p[x]) def union(self, p, x, y): x = self.find(p, x) y = self.find(p, y) if x bool: p = [i f..
266번 문제와 유사하다. 266번은 가능한지 불가능한지만을 true, false로 반환하면 되지만 여기서 불가능하면 깡통([])을 반환하고, true면 구성 가능한 모든 String을 반환하는 것이다. 우선 false의 경우는 266번과 같은 방식을 활용하면 되고, dfs를 통해 String을 구성해 반환하면 된다. class Solution: def __init__(self): self.palL = [] def form(self, even, pal): if len(even) == 0: self.palL.append(pal) return for i in range(len(even)): cur = even[i] copyE = even.copy() copyE.remove(cur) self.form(copy..
주어진 String의 character의 위치만 변경(permutation)해 palindrome이 가능하다면 true 불가능하면 false를 반환하는 문제다. 난이도는 Easy로 아이디어는 매우 간단하다. palindrome의 조건은 String을 앞에서 읽었을 때와 뒤에서 읽었을 때 같은 것으로, String을 구성하는 character의 종류가 모두 짝수거나 한 가지만 홀수를 가질 수 있다. 예를 들어, "aabb"는 palindrome이 되기 위해선 "abba", 혹은 "baab"가 되면 되고 이는 'a' 또는 'b'의 위치 변경을 통해 구성이 가능하고 'a'와 'b'의 개수가 각 2개씩으로 모두 짝수다. "ccbba" 역시 1개(홀수개)인 'a'를 중앙에 위치시켜 "cbabc" 혹은 "bcacb..
157. Read N Characters Given read4의 연장선에 있는 문제로 이 문제 역시 비추천이(1.7K)로 추천(840)을 압도한다. 157번 문제와 다른 점은 완성해야되는 read() 함수가 여러번 불리는 것이다. 그렇기에 이전에 파일의 어디까지 읽었는지를 따로 저장하는 prevI라는 변수와 이전에 파일에서 읽어왔지만 4개까지만 반환이 가능해 아직 반환하지 못했던 내용을 저장해두고 다음에 read() 함수가 호출될 때 전달해주기 위한 버퍼인 prevB 버퍼를 추가하는 것이 핵심이다. 이번엔 Java로 풀어봤다. public class Solution extends Reader4 { /** * @param buf Destination buffer * @param n Number of cha..
문제 설명은 아래와 같다. : Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters. Method read4: The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4. The return value is the number of actual characters read. Note that read4() has its own file pointer, much like FILE *fp in C...
Thomas Connolly와 Carolyn Begg의 저서인 Database Systems, A Practical Approach to Design, Implementation and Management Sixth Edition에 따르면 Funtional Dependency에 대한 정의는 아래와 같다. : Describes the relationship between attributes in a relation. For example, if A and B are attributes of realation R, B is functionally dependent on A, if each value of A is associated with exactly one value of B. (A and B may ..
문제 설명은 아래와 같다. : There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. The cost of painting each house with a certain color is represented by an n x k cost matrix costs. For example, costs[0][0] is the cost of paintin..
Coursera에서 유명한 Andrew Ng 교수님의 Machine Learning 강의 자료는 접근이 가능하고 그 주소는 아래와 같다. Stanford CS229: Machine Learning : Instructors: Andrew Ng, Moses Charikar, Carlos Guestrin https://cs229.stanford.edu/ Syllabus and Course Materials : https://docs.google.com/spreadsheets/d/18pHRegyB0XawIdbZbvkr8-jMfi_2ltHVYPjBEOim-6w/edit#gid=0 Lecture Notes : https://cs229.stanford.edu/notes2022fall/main_notes.pdf
- Total
- Today
- Yesterday
- defaultdict
- java
- tf-idf
- Android
- 머신 러닝
- 리트코드
- DICTIONARY
- 딕셔너리
- machine learning
- 이코노미스트 에스프레소
- I2C
- The Economist Espresso
- 투 포인터
- 소켓 프로그래밍
- Python
- C++
- Computer Graphics
- The Economist
- Hash Map
- 오블완
- leetcode
- 이코노미스트
- socket programming
- 티스토리챌린지
- vertex shader
- join
- min heap
- 파이썬
- 안드로이드
- ml
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |