8000 Merge pull request #41 from seungyeonnnnnni/main · da-in/algorithm-study@50daf47 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 50daf47

Browse files
authored
Merge pull request #41 from seungyeonnnnnni/main
2 parents 422ede3 + 25ac469 commit 50daf47

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def main():
2+
array = [1, 5, 2, 6, 3, 7, 4]
3+
commands = [[2, 5, 3], [4, 4, 1], [1, 7, 3]]
4+
print(solution(array,commands))
5+
6+
7+
def solution(array,commands):
8+
answer = []
9+
for i in range(len(commands)):
10+
arr = array[commands[i][0]-1:commands[i][1]]
11+
arr.sort()
12+
answer.append(arr[commands[i][2]-1])
13+
return answer
14+
15+
if __name__ == "__main__":
16+
main()
17+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from itertools import permutations
2+
maxStr = ""
3+
def main():
4+
# [6, 10, 2]
5+
numbers=[1, 10, 100, 1000, 818, 81, 898, 89, 0, 0]
6+
solution(numbers)
7+
8+
def solution(numbers):
9+
10+
per = list(permutations(numbers,len(numbers)))
11+
12+
rows=len(per)
13+
cols=len(numbers)
14+
arr = [""*cols]*rows
15+
16+
# 비효율. DFS는 시간초과
17+
for i in range(rows):
18+
for j in range(len(per[i])):
19+
arr[i] += str(per[i][j])
20+
arr[i] = int(arr[i])
21+
22+
arr = sorted(arr)
23+
return str(arr[len(arr)-1])
24+
25+
26+
27+
if __name__ == "__main__":
28+
main()
29+
30+
# s = "".join(str(numbers[1]))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import heapq
2+
def solution(scoville,K):
3+
answer = 0
4+
heapq.heapify(scoville)
5+
6+
while(scoville[0]<K):
7+
if len(scoville) == 1 and scoville[0] < K:
8+
return -1
9+
new = heapq.heappop(scoville) + heapq.heappop(scoville)*2
10+
heapq.heappush(scoville,new)
11+
answer+=1
12+
return answer
13+

0 commit comments

Comments
 (0)
0