250x250
Link
λμ GitHub Contribution κ·Έλν
Loading data ...
Notice
Recent Posts
Recent Comments
μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- numpy
- pandas
- ADsP
- DBSCAN
- ν¬λ‘€λ§
- PCA
- νμ΄μ¬
- μ€λ²μνλ§
- Lambda
- ADP
- λ°μ΄ν°λΆμ
- Python
- λΉ λ°μ΄ν°λΆμκΈ°μ¬
- κ΅°μ§ν
- t-test
- λΉ λ°μ΄ν°
- μλν΄λΌμ°λ
- λ°μ΄ν°λΆκ· ν
- λ°μ΄ν°λΆμμ€μ λ¬Έκ°
- opencv
- λ 립νλ³Έ
- datascience
- dataframe
- μ£Όμ±λΆλΆμ
- λ°μ΄ν°λΆμμ λ¬Έκ°
- ν μ€νΈλΆμ
- LDA
- μΈλμνλ§
- λμνλ³Έ
- iloc
Archives
Data Science LAB
[Python] νλ‘κ·Έλλ¨Έμ€ μ½λ©ν μ€νΈ μ°μ΅ level3 (μ΄μ€μ°μ μμν) λ³Έλ¬Έ
π Coding Test/Programmers
[Python] νλ‘κ·Έλλ¨Έμ€ μ½λ©ν μ€νΈ μ°μ΅ level3 (μ΄μ€μ°μ μμν)
γ γ γ γ 2023. 1. 8. 17:57728x90
1. λ¬Έμ μ€λͺ
μ΄μ€ μ°μ μμ νλ λ€μ μ°μ°μ ν μ μλ μλ£κ΅¬μ‘°λ₯Ό λ§ν©λλ€.
λͺ λ Ήμ΄μμ ν(λμ΄)I μ«μ | νμ μ£Όμ΄μ§ μ«μλ₯Ό μ½μ ν©λλ€. |
D 1 | νμμ μ΅λκ°μ μμ ν©λλ€. |
D -1 | νμμ μ΅μκ°μ μμ ν©λλ€. |
μ΄μ€ μ°μ μμ νκ° ν μ°μ° operationsκ° λ§€κ°λ³μλ‘ μ£Όμ΄μ§ λ, λͺ¨λ μ°μ°μ μ²λ¦¬ν ν νκ° λΉμ΄μμΌλ©΄ [0,0] λΉμ΄μμ§ μμΌλ©΄ [μ΅λκ°, μ΅μκ°]μ return νλλ‘ solution ν¨μλ₯Ό ꡬνν΄μ£ΌμΈμ.
2. μ ν μ¬ν
- operationsλ κΈΈμ΄κ° 1 μ΄μ 1,000,000 μ΄νμΈ λ¬Έμμ΄ λ°°μ΄μ λλ€.
- operationsμ μμλ νκ° μνν μ°μ°μ λνλ
λλ€.
- μμλ “λͺ λ Ήμ΄ λ°μ΄ν°” νμμΌλ‘ μ£Όμ΄μ§λλ€.- μ΅λκ°/μ΅μκ°μ μμ νλ μ°μ°μμ μ΅λκ°/μ΅μκ°μ΄ λ μ΄μμΈ κ²½μ°, νλλ§ μμ ν©λλ€.
- λΉ νμ λ°μ΄ν°λ₯Ό μμ νλΌλ μ°μ°μ΄ μ£Όμ΄μ§ κ²½μ°, ν΄λΉ μ°μ°μ 무μν©λλ€.
![](https://blog.kakaocdn.net/dn/cdXIfS/btrVzVwWDQb/CRUvcee6zPimHX9iCT9Rmk/img.png)
3. λ΄ νμ΄
def solution(operations):
answer = []
for i in operations:
if i[0] == 'I':
answer.append(int(i[1:]))
elif i == 'D 1' and len(answer) > 0:
answer.pop(answer.index(max(answer)))
elif i == 'D -1' and len(answer) > 0:
answer.pop(answer.index(min(answer)))
if answer == []:
return [0,0]
return [max(answer), min(answer)]
4. λ€λ₯Έ μ¬λ νμ΄
from heapq import heappush, heappop
def solution(arguments):
max_heap = []
min_heap = []
for arg in arguments:
if arg == "D 1":
if max_heap != []:
heappop(max_heap)
if max_heap == [] or -max_heap[0] < min_heap[0]:
min_heap = []
max_heap = []
elif arg == "D -1":
if min_heap != []:
heappop(min_heap)
if min_heap == [] or -max_heap[0] < min_heap[0]:
max_heap = []
min_heap = []
else:
num = int(arg[2:])
heappush(max_heap, -num)
heappush(min_heap, num)
if min_heap == []:
return [0, 0]
return [-heappop(max_heap), heappop(min_heap)]
728x90
'π Coding Test > Programmers' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Comments