Skip to content

Grace / 3주차 / 2문제 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Grace/binary_search/입국심사.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def solution(n, times):
# 6명이고 7분, 10분 걸림 각각
left = 0
right = max(times) * n
answer = 0

while left <= right:
mid = (left + right) // 2
users = 0 # 심사한 사람 수

for time in times:
users += mid // time
# users가 n보다 큰 경우 탐색이 끝나야 한다.
if users >= n:
break
# users가 n명보다 초과해서 심사하였다면, 시간이 너무 많다는 것이다.
if users >= n:
answer = mid
right = mid -1
# users가 n보다 미만으로 심사하였다면, 시간이 너무 부족한 것이다.
else:
left = mid + 1

return answer
19 changes: 19 additions & 0 deletions Grace/dfs_bfs/타겟 넘버.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def solution(numbers, target):
leaves = [0]
answer = 0 # 카운트

for num in numbers:
temp = []

for leaf in leaves:
temp.append(leaf + num)
temp.append(leaf - num)

leaves = temp

# 타겟과 같은지를 확인
for leaf in leaves:
if leaf == target:
answer += 1

return answer
16 changes: 16 additions & 0 deletions Grace/dynamic_programming/N으로 표현.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def solution(N, number):
dp = [set([int(str(N) * i)]) for i in range(1, 9)]

for i in range(8):
for j in range(i):
# j 개
for num1 in dp[j]:
for num2 in dp[i-j-1]:
dp[i].add(num1 + num2)
dp[i].add(num1 - num2)
dp[i].add(num1 * num2)
if num2 != 0:
dp[i].add(num1 // num2)
if number in dp[i]:
return i+1
return -1
14 changes: 14 additions & 0 deletions Grace/hash/전화번호 목록.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def solution(phone_book):
# 1. Hash map을 만든다
hash_map = {}
for phone_number in phone_book:
hash_map[phone_number] = 1

for phone_number in phone_book:
jubdoo = ""
for number in phone_number:
jubdoo += number

if jubdoo in hash_map and jubdoo != phone_number:
return False
return True
7 changes: 7 additions & 0 deletions Grace/sort/K번째수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def solution(array, commands):
answer = []
for i in range(len(commands)):
tmp_arr = array[commands[i][0]-1:commands[i][1]]
tmp_arr.sort()
answer.append(tmp_arr[commands[i][2]-1])
return answer
Empty file.
18 changes: 18 additions & 0 deletions Grace/stack_queue/프로세스.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from collections import deque

def solution(priorities, location):
answer = []
queue = deque((i, j) for i, j in enumerate(priorities))

while queue:
process = queue.popleft()
# 우선순위가 더 높은 프로세스가 하나라도 있으면 큐에 다시 추가 / 아니면 해당 프로세스 실행
if queue and any(process[1] < q[1] for q in queue):
queue.append(process)
else:
answer.append(process)

# location 실행 순서 찾기
for i in answer:
if i[0] == location:
return answer.index(i)+1