목록전체 글 (76)
one line of code at a time
이진 트리의 inorder traversal class Solution: def dfs(self, root, answer): if root is None: return self.dfs(root.left, answer) answer.append(root.val) self.dfs(root.right, answer) def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: answer = [] self.dfs(root, answer) return answer
The intuition of Two's Complement Representation of Signed Integers- Big idea: Negate the value of the highest order bit and treat every other bit the same.- 가장 큰 bit에 +/-의 의미를 부여하고, 나머지 bit는 똑같음. Negation of a Two's Complement Value- To negate any signed-value with Two's Complement representation: (1) Take the complement of all bits (0 to 1, 1 to 0)(2) Add 1The least significant bit (LSB) of a ..
Computers are state machines built from simple raw materials:A transistor is an electronic switch with two states: ON and OFFA capacitor stores electric enery of a positive or negative chargeThese two building blocks can be paired to from a DRAM memory cellYour computer likely has over 68,719,476,736 DRAM memory cells.Each stores one bit of information. A bit has two states: 1 or 0.The programs ..
트랜지스터는 '스위치'다. TransistorsTwo types of transistors nMospMos behaves as an open switch whenVg is low (0)Vg is highbehaves as an closed switch whenVg is high (1)Vg is low nMos TransistorsAct as a open switch when the gate voltage (Vg) is lowMeaning that current cannot flow between source and drainAct as a closed switch when the gate voltage (Vg) is highMeaning that current can flow between source ..
논문 분석이 논문의 motivation은 CNN + LSTM 아키텍처인 LRCN이 대량의 데이터셋 (large-scale dataset)에서는 그렇게 효율적이지 못하다는 이다. 이 논문은 영상 분석에서 3D 컨볼루션 네트워크를 제안한다. 2D는 spatial feature만 잡아낼 수 있지만, 3D CNN은 spatial + temporal feature를 잡아낼 수 있다. 3 x 3 컨볼루션 연산이 아닌 3 x 3 x 3 연산을 하는 것이다. 이 논문에서 실험을 다양하게 했는데 3 x 3 x 3 커널 연산이 성능이 가장 좋았다고 한다. 추가된 1차원으로 spatiotemporal information/feature를 학습하게 된다. 3D CNN 아키텍처는 다음과 같다. 8개의 3D 컨볼루션 레이어, 5..
논문 분석이 논문은 Long-term Recurrent Convolutional Networks forVisual Recognition and Description (LRCN)이라는 새로운 아키텍처를 제안했다. 이 모델은 시간과 공간 상에서 visual dependencies를 학습할 수 있다. (The proposed model enables learning visual dependencies in space and time) LRCN 아키텍처는 크게 input, CNN layer, LSTM layer, 그리고 output 이렇게 4가지 파트로 되어 있다. CNN은 visual feature를 추출해내고, LSTM은 sequence 학습을 담당한다. input은 영상 클립을 프레임 단위로 나눈 이..
https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/ 중간 노드를 삭제한 연결 리스트를 반환하는 문제다. 연결 리스트에서 중간 노드를 반환하는 건 slow, fast 이렇게 두 개의 포인터를 쓰면 된다. 그런데 이 문제에서는 중간 노드를 제거해야 한다. 연결리스트에서는 종종 head 앞에 가상의 노드를 하나 더 추가하면 쉽게 문제를 풀 수 있다.dummy 노드를 만들어준다.dummy = ListNode(next=head) 그런 다음에 slow 포인터를 dummy에 놓고, fast 포인터를 head에 놓는다.slow, fast = dummy, head leetcode 876번 중간 노드 찾기 문제에서는 slow, fast 둘 다 ..
https://leetcode.com/problems/middle-of-the-linked-list/description/ 연결리스트의 중간 지점을 구하는 문제이다. fast, slow 이렇게 두 개의 포인터를 활용하면 쉽게 중간 지점을 구할 수 있다. # Definition for singly-linked list.# class ListNode(object):# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution(object): def middleNode(self, head): slow, fast = head, head while fas..
https://leetcode.com/problems/number-of-provinces/ n개의 도시 (aka. 노드)가 있는데 이 도시들이 직접적으로나 간접적으로 연결이 되면, 하나의 province로 간주한다. 그렇게 했을 때 총 몇 개의 province가 있는지 구하는 문제이다. isConnected 라는 인접 행렬 (adjacent matrix)이 주어져 있다. class Solution(object): def findCircleNum(self, isConnected): num_prov = 0 visited = set() def dfs(start): pass return num_prov 처음 뼈대는 이렇게 잡을 수 있..
그래프 순회를 할 때 2가지 방법이 있다. BFS가 있고, DFS가 있다. 트리 순회를 할 때에도 BFS로 할 수도 있고, DFS로 할 수도 있다.BFS가 옆으로 가는 느낌이라면,DFS는 밑으로 끝까지 쭉 가서 단말노드에 닿을 때까지 가는 느낌이다. DFS를 미로찾기로 이해하면 쉽다. 막다른 곳으로 가더라도 쭉 간 다음에 아니면 돌아오고 (백트래킹), 또 쭉 가보고 하다가 도착 지점에 짠하고 도착할 수 있다. 파이썬에서 DFS를 구현하려면 stack이라는 자료 구조를 써야 한다.스택을 통해서 방문한 노드를 저장하는 것이다. 스택은 last in first out (LIFO)이다.루트 노드로 시작해서 루트 노드를 pop 한 다음에 루트 노드와 연결된 모든 노드들을 스택에 넣는다.스택이 empty 될 때..