Skip to content

Commit a8f55a1

Browse files
committed
commit
2 parents 9cdddb9 + 95f601f commit a8f55a1

File tree

189 files changed

+1449
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+1449
-25
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def solution(lottery):
2+
answer = -1
3+
4+
arr = [0] * 1001
5+
visited = [0] * 1001
6+
sum = 0
7+
count = 0
8+
for i in range(len(lottery)):
9+
if lottery[i][1] == 0 and visited[lottery[i][0]] == 0:
10+
arr[lottery[i][0]] += 1
11+
else:
12+
visited[lottery[i][0]] = 1
13+
14+
for i in range(1000):
15+
if visited[i]:
16+
sum += arr[i]
17+
count += 1
18+
#print(sum, count)
19+
20+
if sum:
21+
answer = (sum+count) // count
22+
else:
23+
answer = 0
24+
25+
return answer
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from _collections import deque
2+
3+
4+
5+
dx = [-1, 1, 0, 0] #상하좌우
6+
dy = [0, 0, -1, 1]
7+
8+
def solution(grid):
9+
answer = 0
10+
row = len(grid)
11+
col = len(grid[0])
12+
map = [[1e9] * col for _ in range(row)]
13+
map[0][0] = grid[0][0]
14+
q = deque()
15+
q.append((0, 0))
16+
17+
while q:
18+
x, y = q.popleft()
19+
for i in range(4):
20+
nx = x + dx[i]
21+
ny = y + dy[i]
22+
if 0 <= nx < row and 0 <= ny < col:
23+
if map[x][y] + grid[nx][ny] < map[nx][ny]:
24+
map[nx][ny] = map[x][y] + grid[nx][ny]
25+
q.append((nx, ny))
26+
27+
28+
answer = map[row-1][col-1]
29+
30+
31+
return answer
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from _collections import deque
2+
import copy
3+
4+
def dfs(a, k):
5+
q = deque()
6+
7+
for i in range(len(a)):
8+
if a[i] =
9+
10+
11+
return
12+
13+
def solution(arr, k):
14+
answer = -1
15+
a = copy.deepcopy(arr)
16+
dfs(a, k)
17+
18+
return answer
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
def solution(n, results):
22
answer = 0
3-
3+
44
return answer
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from _collections import deque
2+
3+
4+
def solution(priorities, location):
5+
answer = 0
6+
7+
q = deque()
8+
result = deque()
9+
10+
for i in range(len(priorities)):
11+
q.append((priorities[i], i)) # 우선 순위랑 인덱스 순서로 넣어준다
12+
13+
print(q)
14+
15+
while q:
16+
pri, index = q.popleft()
17+
flag = 0
18+
#print('pri, index = ', pri, index)
19+
for i in range(len(q)):
20+
if q[i][0] > pri:
21+
#print('if')
22+
q.append((pri, index))
23+
flag = 1
24+
break
25+
if flag == 0:
26+
result.append((pri, index))
27+
#print('i = ', i, q)
28+
29+
#print(result)
30+
31+
for i in range(len(result)):
32+
if result[i][1] == location:
33+
answer = i + 1
34+
35+
return answer
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
def solution(numbers):
2-
32
answer = ''
4-
count = 0
5-
for i in range(len(numbers)):
6-
count += len(str(numbers[i])) # i번째 숫자의 자리수를 더해줘서 총 자리수 구하기
7-
8-
9-
10-
return answer
113

12-
9
13-
---------
4+
num = list(map(str, numbers))
5+
num.sort(key=lambda x: x*3, reverse=True)
146

15-
7.51
167

17-
7.53
188

19-
753
20-
755
9+
for i in range(len(num)):
10+
answer += num[i]
2111

22-
7.92
12+
zero_flag = 0
13+
for i in range(len(answer)):
14+
if answer[i] != '0':
15+
zero_flag = 1
2316

24-
75 / 10 = 7.55
17+
if zero_flag == 0:
18+
return '0'
2519

26-
7 7.77
27-
28-
7 7.77
29-
30-
8
31-
32-
9
20+
return answer
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(phone_book):
2+
answer = True
3+
phone_book.sort()
4+
5+
# for a in range(len(phone_book)-1):
6+
# len_a = len(phone_book[a])
7+
# for b in range(a+1, len(phone_book)):
8+
# if phone_book[a] in phone_book[b][:len_a]:
9+
# answer = False
10+
11+
for a in range(len(phone_book) - 1):
12+
len_a = len(phone_book[a])
13+
if phone_book[a] in phone_book[a+1][:len_a]:
14+
answer = False
15+
16+
17+
return answer

cmkim/이것이 취업을 위한 코딩 테스트다/안테나_360p.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# print(a[(n - 1) // 2])
66

77

8-
98
n = int(input())
109
arr = []
1110
arr = list(map(int, input().split()))

cmkim/이것이 취업을 위한 코딩 테스트다/특정 거리의 도시 찾기_339p.py

Whitespace-only changes.

mhkim/dfsbfs-19.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
@file dfsbfs-19.py
3+
@brief 연산자 끼워넣기
4+
@desc dfs
5+
"""
6+
7+
INF = int(1e9)+1
8+
9+
n = int(input())
10+
numbers = list(map(int, input().split()))
11+
ops = list(map(int, input().split())) # +,-,*,/
12+
13+
maxVal = -INF
14+
minVal = INF
15+
16+
17+
def dfs(cnt, hap, ops):
18+
global maxVal
19+
global minVal
20+
21+
if cnt == n:
22+
maxVal = max(hap, maxVal)
23+
minVal = min(hap, minVal)
24+
return
25+
26+
if ops[0] > 0:
27+
ops[0] -= 1
28+
dfs(cnt+1, hap+numbers[cnt], ops)
29+
ops[0] += 1
30+
31+
if ops[1] > 0:
32+
ops[1] -= 1
33+
dfs(cnt+1, hap-numbers[cnt], ops)
34+
ops[1] += 1
35+
36+
if ops[2] > 0:
37+
ops[2] -= 1
38+
dfs(cnt+1, hap*numbers[cnt], ops)
39+
ops[2] += 1
40+
41+
if ops[3] > 0:
42+
ops[3] -= 1
43+
if hap < 0:
44+
dfs(cnt+1, -(-hap//numbers[cnt]), ops)
45+
else:
46+
dfs(cnt+1, hap//numbers[cnt], ops)
47+
ops[3] += 1
48+
49+
50+
dfs(1, numbers[0], ops)
51+
52+
print(maxVal)
53+
print(minVal)

0 commit comments

Comments
 (0)