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 |
Tags
- 항해플러스
- 항해99
- Python
- Algorithm
- java
- programmers
- sw expert academy
- 코딩테스트합격자되기
- 이코테
- redux-toolkit
- Get
- 리액트
- SW
- react-redux
- redux
- react
- react-router
- json-server
- 자바
- 테코테코
- 프로그래머스
- redux-saga
- 매일메일
- axios
- createSlice
- maeil-mail
- C++
- JavaScript
- 알고리즘
- useDispatch
Archives
- Today
- Total
Binary Journey
[프로그래머스] 프린터 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
** Python
def solution(priorities, location):
answer = 0
queue = [(i, priority) for i, priority in enumerate(priorities)]
while True:
now = queue.pop(0)
if any(now[1] < q[1] for q in queue):
queue.append(now)
else:
answer += 1
if now[0] == location:
return answer
return answer
any는 javascript 의 some과 유사한 기능을 한다.
if (queue.some(q => q[1] > now[1])
참고: https://jinomadstory.tistory.com/17
** Javascript
function solution(priorities, location) {
var answer = 0;
let queue = priorities.map((p, i) => ([i, p]));
while (true) {
const now = queue.shift();
if (queue.some(q => q[1] > now[1])) {
queue.push(now);
} else {
answer++;
if (now[0] == location) return answer;
}
}
return answer;
}
반응형
'프로그래머스 > level 2' 카테고리의 다른 글
[프로그래머스] 행렬 테두리 회전하기 (0) | 2022.05.12 |
---|---|
[프로그래머스] 거리두기 확인하기 (0) | 2022.05.12 |
[프로그래머스] 튜플 (0) | 2022.04.28 |
[프로그래머스] 전화번호 목록 (0) | 2022.04.21 |
[프로그래머스] 삼각달팽이 (0) | 2022.04.21 |