티스토리 뷰
https://programmers.co.kr/learn/courses/30/lessons/42862
def solution(n, lost, reserve):
student = {}
for i in range(n):
student[i + 1] = 1
for l in lost:
if l in student:
student[l] -= 1
for r in reserve:
if r in student:
student[r] += 1
answer = 0
for key in student.keys():
if student[key] == 0 and key == 1:
if student[key + 1] == 2:
student[key] += 1
student[key + 1] -= 1
elif student[key] == 0 and (2 <= key <= n - 1):
if student[key - 1] == 2:
student[key - 1] -= 1
student[key] += 1
elif student[key + 1] == 2:
student[key + 1] -= 1
student[key] += 1
elif student[key] == 0 and key == n:
if student[key - 1] == 2:
student[key - 1] -= 1
student[key] += 1
for i in student.values():
if i >= 1:
answer += 1
return answer
def solution(n, lost, reserve):
answer = 0
for i in range(1, n + 1):
if i not in lost:
answer += 1
elif i in reserve:
answer += 1
lost.remove(i)
reserve.remove(i)
for i in lost:
if i - 1 in reserve:
answer += 1
reserve.remove(i - 1)
elif i + 1 in reserve:
answer += 1
reserve.remove(i + 1)
return answer
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- SCSS
- 파이썬
- 인프런
- 알고리즘
- Java
- python
- 플로이드워셜
- springboot
- 에라토스테네스의체
- frontend
- 웹팩
- 백준
- html
- 다익스트라
- MST
- controller
- heapq
- 자바스크립트
- javascript
- 1급객체
- 투포인터
- BOJ
- js
- 고차함수
- CSS
- webpack
- BFS
- 최소공통조상
- 위상정렬
- 최소스패닝트리
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함