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 binary_search(arr, x): | |
if len(arr) == 0: | |
return False | |
elif len(arr) == 1: | |
return True if arr[0] == x else False | |
mid = len(arr)//2 | |
if arr[mid] == x: | |
return True | |
elif arr[mid] > x: |
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 bfs(graph, root): | |
visited = [] | |
queue = [root] | |
while queue: | |
node = queue.pop(0) | |
if node not in visited: | |
visited.append(node) | |
queue.extand(graph[node]) | |
return visited |
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 fill_tiles(N): | |
a=b=1 | |
for _ in range(N): | |
a,b=b,a+b | |
return a | |
print(fill_tiles(12)) |
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 alarm(): | |
''' | |
백준 2884 | |
''' | |
H , M = map(int, input().split()) | |
total = H * 60 + M - 45 | |
if total < 0: | |
total += 60 *24 | |
H = total // 60 | |
M = total % 60 |
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 heapq | |
def find_mid(arr): | |
''' | |
leetcode 295 | |
''' | |
mid = [] | |
small = [] # 최대힙 | |
large = [] # 최소힙 | |
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 itertools | |
def get_prime_number(numbers): | |
''' | |
프로그래머스 42839 소수 찾기(완전 탐색) | |
''' | |
answer = 0 | |
l = [n for n in numbers] | |
# 만들 수 있는 수 순열 만들기 |
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
''' | |
https://wikidocs.net/105425 | |
''' | |
import bisect | |
result = [] | |
for score in [33, 99, 77, 70, 89, 90, 100]: | |
pos = bisect.bisect([60, 70, 80, 90], score) # 점수를 삽입할 위치 반환 | |
grade = 'FDCBA'[pos] | |
result.append(grade) |
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
animals = ['dog', 'cat', 'rabbit', 'tiger'] | |
dic = {} | |
for animal in animals: | |
if animal in dic.keys(): | |
dic[animal] += 1 | |
else: | |
dic[animal] = 1 | |
print(dic) | |
''' | |
기본적인 딕셔너리 사용법 |
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
''' | |
백준 15649. 1 ~ N으로 M개짜리 조합 만들기 | |
''' | |
n,m = list(map(int,input().split())) | |
s = [] | |
def dfs(): | |
if len(s)==m: | |
print(' '.join(map(str,s))) |
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
''' | |
백준 1260. bfs, dfs | |
''' | |
from collections import defaultdict | |
# 양방향 그래프 만들기 | |
n, m, v = map(int, input().split()) | |
graph = defaultdict(list) | |
for i in range(m): | |
n1, n2 = map(int, input().split()) | |
graph[n1].append(n2) |
OlderNewer