This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# from : https://programmers.co.kr/learn/courses/30/lessons/43163?language=python3 | |
class Node: | |
def __init__(self, data): | |
self.visited = False | |
self.data = data | |
class Stack: | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(participant, completion): | |
hash_map = {} | |
length = len(completion) | |
for i in range(length): | |
c = completion[i] | |
if hash_map.get(c) == None: | |
hash_map[c] = 1 | |
else: | |
hash_map[c] = hash_map[c] + 1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
q = deque() | |
def bfs(index, computers): | |
q.append(index) | |
while not (len(q) == 0): | |
i = q.popleft() | |
computers[i][i] = 0 | |
for z in range(len(computers[i])): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def solution(n): | |
parent = math.factorial(2*n) | |
child = math.factorial(n) * math.factorial(n+1) | |
return parent / child |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def get_brown(width, height) : | |
return 2*(width) + 2*(height+2) | |
def solution(brown, red): | |
carpet_width = 0 | |
carpet_height = 0 | |
elements = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def swap(list, a, b) : | |
temp = list[b] | |
list[b] = list[a] | |
list[a] = temp | |
def getChildren(lastIndex, parent) : | |
# parent가 더 작은걸 명심하자 | |
childLeft = (parent * 2) + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Node : | |
val = 0 | |
left = None | |
right = None | |
def __init__(self, val, left = None, right = None) : | |
self.val = val | |
self.left = left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Node : | |
val = 0 | |
left = None | |
right = None | |
def __init__(self, val, left = None, right = None) : | |
self.val = val | |
self.left = left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Node : | |
val = 0 | |
def __init__(self, val) : | |
self.val = val | |
leftNode = Node(100) | |
rightNode = Node(200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d1 = [0, 1, 1, 1] | |
d2 = [1, 0, 1, 1] | |
dc = [2, 0, 2, 2] | |
def findCosineSimilarity(d1, d2) : | |
sum = 0. | |
d1_len = 0 | |
d2_len = 0 | |
for i in range(len(d1)) : | |
sum = (sum + d1[i] + d2[i]) |