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
- C++
- react-redux
- createSlice
- Python
- 항해플러스
- 매일메일
- Get
- programmers
- 알고리즘
- SW
- react-router
- 이코테
- 리액트
- 자바
- react
- 테코테코
- json-server
- redux-saga
- sw expert academy
- java
- useDispatch
- redux-toolkit
- redux
- Algorithm
- axios
- maeil-mail
- 코딩테스트합격자되기
- 프로그래머스
- JavaScript
- 항해99
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
[프로그래머스] '프린터' 알고리즘 풀이 - Python
Contents 문제 설명 [제한사항] [입출력 예] 알고리즘 분석 [나의 풀이] [Most 1의 풀이] [Most 2의 풀이] 문제 설명 일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요
jinomadstory.tistory.com
** 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 |