Skip to content

Commit e78f4bd

Browse files
committed
Lv2 파이썬 완료
1 parent 1af1c83 commit e78f4bd

38 files changed

+596
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def solution(n):
2+
answer = ''
3+
arr = [1, 2, 4]
4+
r = -1
5+
6+
while n > 0:
7+
n -= 1
8+
r = n % 3
9+
answer += str(arr[n % 3])
10+
n = n // 3
11+
12+
answer = answer[::-1]
13+
14+
return answer

Programmers/Lv2/Lv2_H-Index.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def solution(citations):
2+
answer = 0
3+
citations.sort(reverse=True)
4+
for i in range(len(citations)):
5+
if i+1 > citations[i]: # 처음으로 넘는 인덱스가 나오면
6+
return i # 이전 인덱스 반환
7+
return len(citations)
8+
9+
print(solution([0, 1, 3, 5, 6]))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def solution(s):
2+
answer = ''
3+
flag = True
4+
for i in s:
5+
if flag and not i.isdigit():
6+
answer += i.upper()
7+
flag = False
8+
else:
9+
answer += i.lower()
10+
flag = False
11+
12+
if i.isspace():
13+
flag = True
14+
return answer
15+
16+
print(solution("332people #unFollowed m3e "))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import fractions
2+
def solution(arr):
3+
answer = arr[0]
4+
for i in arr:
5+
answer = i * answer / fractions.gcd(i, answer)
6+
return answer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import functools
2+
3+
def comparator(a,b):
4+
t1 = a+b
5+
t2 = b+a
6+
return int(t1) - int(t2) # t1이 크다면 1, t2가 크다면 -1 같으면 0
7+
8+
def solution(numbers):
9+
n = [str(x) for x in numbers]
10+
n = sorted(n, key=functools.cmp_to_key(comparator),reverse=True)
11+
return str(int(''.join(n)))
12+
13+
print(solution([3, 30, 34, 5, 9]))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def solution(board):
2+
answer = 0
3+
xlen = len(board[0])
4+
ylen = len(board)
5+
6+
if xlen < 2 or ylen < 2: # 가로, 세로 중 하나라도 길이가 1이라면
7+
for i in range(ylen):
8+
for j in range(xlen):
9+
if board[i][j] == 1:
10+
answer = 1
11+
else:
12+
for i in range(1,ylen):
13+
for j in range(1,xlen):
14+
if board[i][j] == 1:
15+
board[i][j] = min(board[i][j - 1], board[i - 1][j], board[i - 1][j - 1]) + 1
16+
if answer < board[i][j]:
17+
answer = board[i][j]
18+
return answer * answer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def solution(people, limit):
2+
answer = 0
3+
people.sort(reverse=True) # 내림차순 정렬
4+
a = 0
5+
b = len(people)-1
6+
while a<=b:
7+
if people[a] + people[b] <= limit:
8+
b -= 1
9+
answer += 1
10+
a += 1
11+
return answer
12+
13+
print(solution([70, 80, 50], 100))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def solution(progresses, speeds):
2+
answer = []
3+
temp = []
4+
for i, j in zip(progresses, speeds):
5+
diff = 100 - i
6+
count = 0
7+
if diff%j==0:
8+
count = diff//j
9+
else:
10+
count = (diff//j)+1
11+
temp.append(count)
12+
temp.reverse()
13+
while len(temp)>0:
14+
t1 = temp[-1] # 최상위
15+
t2 = 1 # 1개로 초기화
16+
temp.pop() # 제거
17+
while len(temp)!=0 and temp[-1] <= t1: # 최상위가 나랑 같거나 작으면 추가
18+
temp.pop()
19+
t2 += 1
20+
answer.append(t2)
21+
return answer
22+
23+
print(solution( [93, 30, 55], [1, 30, 5]))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(bridge_length, weight, truck_weights):
2+
q = []
3+
time = 0
4+
total = 0
5+
6+
while len(truck_weights) > 0 or len(q) > 0:
7+
time += 1
8+
if len(q) > 0 and time - q[0][1] == bridge_length:
9+
temp = q.pop(0)[0]
10+
total -= temp
11+
12+
if len(truck_weights) > 0 and total + truck_weights[0] <= weight:
13+
next = truck_weights.pop(0)
14+
q.append((next, time))
15+
total += next
16+
17+
return time
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def solution(n):
2+
tc = bin(n).count('1')
3+
for i in range(n+1, 1000001):
4+
if bin(i).count('1') == tc:
5+
return i

0 commit comments

Comments
 (0)