Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- Python
- 크로스핏
- 회전하는큐
- 4811
- 그리디
- 26008
- D1
- 1781
- sw expert academy
- 15662
- 재귀함수
- Flutter
- spring boot
- 14863
- DP
- Crossfit
- BOJ14889
- 삼성
- 재귀
- 동적프로그래밍
- 1로만들기2
- 해시해킹
- C++
- 15353
- 브루트포스
- 백준
- BOJ
- 스택
- dart
- 서울에서경산까지
Archives
- Today
- Total
곧죽어도 콛잉
[프로그래머스 / Python] 프로세스 본문
https://school.programmers.co.kr/learn/courses/30/lessons/42587
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
오 우선순위 큐 아니야 하면서 heapq로 최대힙 구현해서 풀려고 했는데
보니깐 아니였다...
그래서 그냥 큐를 만들어서 나온 로직대로 구현했다.
그런데 역시 python 답게 더 짧게 구하는 풀이가 있었다!
바로 any랑 enumerate 사용!
멋진 풀이다.
from collections import deque
def solution(priorities, location):
h = [[priorities[i], i] for i in range(len(priorities))]
q = deque(h)
answer = 0
while q :
t = q.popleft()
chk = True
for i in q :
if i[0] > t[0] :
q.append(t)
chk = False
break
if chk : answer+=1
if chk and t[1] == location :
return answer
any 함수, enumerate 이용하기
def solution(priorities, location):
queue = [(i,p) for i,p in enumerate(priorities)]
answer = 0
while True:
cur = queue.pop(0)
if any(cur[1] < q[1] for q in queue):
queue.append(cur)
else:
answer += 1
if cur[0] == location:
return answer
'Coding Test > Python' 카테고리의 다른 글
[BOJ 1158 / Python] 요세푸스 문제 (0) | 2024.02.27 |
---|---|
[프로그래머스 / Python] 의상 (0) | 2024.02.26 |
[BOJ 26008 / Python] 해시해킹 (0) | 2024.02.26 |
[프로그래머스 / Python] 나누어 떨어지는 숫자 배열 (0) | 2024.02.21 |
[BOJ 10818 / Python] 최소, 최대 (0) | 2024.02.21 |
Comments