diff --git "a/Grace/binary_search/\354\236\205\352\265\255\354\213\254\354\202\254.py" "b/Grace/binary_search/\354\236\205\352\265\255\354\213\254\354\202\254.py" new file mode 100644 index 0000000..6a843cd --- /dev/null +++ "b/Grace/binary_search/\354\236\205\352\265\255\354\213\254\354\202\254.py" @@ -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 \ No newline at end of file diff --git "a/Grace/dfs_bfs/\355\203\200\352\262\237 \353\204\230\353\262\204.py" "b/Grace/dfs_bfs/\355\203\200\352\262\237 \353\204\230\353\262\204.py" new file mode 100644 index 0000000..bb0a38a --- /dev/null +++ "b/Grace/dfs_bfs/\355\203\200\352\262\237 \353\204\230\353\262\204.py" @@ -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 \ No newline at end of file diff --git "a/Grace/dynamic_programming/N\354\234\274\353\241\234 \355\221\234\355\230\204.py" "b/Grace/dynamic_programming/N\354\234\274\353\241\234 \355\221\234\355\230\204.py" new file mode 100644 index 0000000..3f6ed28 --- /dev/null +++ "b/Grace/dynamic_programming/N\354\234\274\353\241\234 \355\221\234\355\230\204.py" @@ -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 \ No newline at end of file diff --git "a/Grace/hash/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" "b/Grace/hash/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" new file mode 100644 index 0000000..5a7b010 --- /dev/null +++ "b/Grace/hash/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" @@ -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 \ No newline at end of file diff --git "a/Grace/sort/K\353\262\210\354\247\270\354\210\230.py" "b/Grace/sort/K\353\262\210\354\247\270\354\210\230.py" new file mode 100644 index 0000000..aaf8965 --- /dev/null +++ "b/Grace/sort/K\353\262\210\354\247\270\354\210\230.py" @@ -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 \ No newline at end of file diff --git "a/Grace/stack_queue/\354\243\274\354\213\235\352\260\200\352\262\251.py" "b/Grace/stack_queue/\354\243\274\354\213\235\352\260\200\352\262\251.py" new file mode 100644 index 0000000..e69de29 diff --git "a/Grace/stack_queue/\355\224\204\353\241\234\354\204\270\354\212\244.py" "b/Grace/stack_queue/\355\224\204\353\241\234\354\204\270\354\212\244.py" new file mode 100644 index 0000000..4d615aa --- /dev/null +++ "b/Grace/stack_queue/\355\224\204\353\241\234\354\204\270\354\212\244.py" @@ -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 \ No newline at end of file