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 os | |
class SubUtility: | |
def __init__(self): | |
self.init = None | |
def ConfigToDict(self, filename): | |
equal_option = dict() | |
if os.path.isfile(filename): | |
with open(filename, 'r') as fileread: |
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 java.util.*; | |
public int solution(int k, int[] tangerine) { | |
int answer = 0; | |
HashMap<Integer,Integer> map =new HashMap<>(); | |
for (int t : tangerine) { | |
map.put(t, map.getOrDefault(t, 0) + 1); | |
} | |
List<Integer> list = new ArrayList<>(map.keySet()); |
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 carFleet(self, target: int, position: List[int], speed: List[int]) -> int: | |
''' | |
Leetcode 853. Car Fleet | |
stack을 사용 p는 절편, (x, s*x)의 선분을 좌표평면에 그리고 절편 큰 순서로 add, 절편이 더 크면서 기울기가 작으면 target 전에 만나기 때문에 pop | |
stack의 남은 길이는 아직 만나지 못한 차량의 개수 | |
''' | |
pair = [[p, s] for p, s in zip(position, speed)] | |
stack = [] | |
for p, s in sorted(pair)[::-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
''' | |
백준 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) |
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
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
''' | |
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
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
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
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 |
NewerOlder