-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking โSign up for GitHubโ, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-H0ngJu #151
1-H0ngJu #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
## โ๏ธ ๊ธฐ๋ก | ||
## โ๏ธ ๊ธฐ๋ก | ||
|
||
| ์ฐจ์ | ๋ ์ง | ๋ฌธ์ ์ ํ | ๋งํฌ | ํ์ด | | ||
| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | ||
| 1์ฐจ์ | 2024.03.05 | ํ | [ํ๋ก์ธ์ค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | | ||
|
||
| ์ฐจ์ | ๋ ์ง | ๋ฌธ์ ์ ํ | ๋งํฌ | ํ์ด | | ||
|:----:|:---------:|:----:|:-----:|:----:| | ||
| 1์ฐจ์ | 2024.03.04 | BFS | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/169199">๋ฆฌ์ฝ์ณ ๋ก๋ด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/1 | | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from collections import deque | ||
|
||
def solution(priorities, location): | ||
answer = 0 | ||
queue = deque([(i, k) for k, i in enumerate(priorities)]) # ํํ ํ ์์ฑ | ||
priorities.sort(reverse=True) # ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ | ||
|
||
while queue: | ||
cur = queue.popleft() # ๊ฐ์ฅ ์์ ํ๋ก์ธ์ค ๊บผ๋ด๊ธฐ (queue.pop(0)) | ||
if cur[0] == priorities[0]: # ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌ๋ ์ฐ์ ์์ == ํ์ฌ ์์ -> ๊ฐ์ฅ ๋์ | ||
answer += 1 # ์ ++ | ||
if cur[1] == location: # ์ฐพ๊ณ ์ํ๋ process์ธ ๊ฒฝ์ฐ | ||
break | ||
priorities.pop(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์๋๋ฉด ๊ตณ์ด ์ด๋ ๊ฒ ํ๊ธฐ ์ซ์ผ๋ฉด ์์ ์ฐ์ ์์๋ฅผ ์ ๋ ฌํ๋ ์ฝ๋๋ฅผ ์๋์ ๊ฐ์ด ์ค๋ฆ์ฐจ์์ผ๋ก ๋ฐ๊พธ๊ณ , priorities.sort() # ์ค๋ฆ์ฐจ์ ์ ๋ ฌ while queue:
cur = queue.popleft() # ๊ฐ์ฅ ์์ ํ๋ก์ธ์ค ๊บผ๋ด๊ธฐ (queue.pop(0))
if cur[0] == priorities[-1]: # ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ๋ ์ฐ์ ์์ ๋ง์ง๋ง ํญ == ํ์ฌ ์์ -> ๊ฐ์ฅ ๋์
answer += 1 # ์ ++
if cur[1] == location: # ์ฐพ๊ณ ์ํ๋ process์ธ ๊ฒฝ์ฐ
break
priorities.pop() ๋ก ํ๋ฉด ๋งค๋ฒ ์ฐ์ ์์๋ฅผ ๋ฝ์ ๋ ๋ง๋ค ์ง๊ธ์ ์ด ์ ๋ ์๋ฃ ๊ตฌ์กฐ์ ์๊ฐ ๋ณต์ก๋ ์ด๋์ ๋ฏธ๋ฆฌ ์ฒดํ์ํค๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ๋ค์...! ์์ง ์๋ฃ ๊ตฌ์กฐ๋ณ ์๊ฐ ๋ณต์ก๋๊ฐ ์ฒดํ๊ฐ ์๋์ จ์ผ๋ฉด ์คํ, ํ, ํ ๋ฌธ์ ๋ฅผ ์ง์ค์ ์ผ๋ก ํ์ด์ ์ฒดํ์์ผ๋ ์ข์ ๊ฒ ๊ฐ์์. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ๋ฌธ์ ํ ๋น์์๋ pop๊ณผ popleft์ ์ฐจ์ด๋ฅผ ๋ชฐ๋๋๋ฐ, ์ฝ๋ ๋ฆฌ๋ทฐํ๊ณ ๋ค์ ์ ์ฝ๋๋ฅผ ๋ณด๋๊น pop๋ณด๋ค popleft๊ฐ ๋ ์ข์๊ฒ ๋ค๋๊ฒ ๋์ ๋ณด์ด๋ค์ ใทใท ์คํ, ํ, ํ ๋ฌธ์ ๋ ์ง์ค์ ์ผ๋ก ํ์ด๋ณด๊ฒ ์ด๋ค -! |
||
else: | ||
queue.append(cur) # ๋ค๋ก ๋ฏธ๋ฃจ๊ธฐ | ||
|
||
return answer | ||
|
||
#test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ ์ง์ง ๋ฌธ์ ๋๋ก ๊ตฌํํด์ ํ์์๋๋ฐ,
์ด์ฐจํผ ์ฐ์ ์์๊ฐ ๋์ ์ ๋ค ๋ถํฐ ๋จผ์ ๋์์ผ ํ๋ ์ ๋ ฌํด์ ํ๋์ฉ ๋ฝ๋ ๊ฒ๋ ์์ด๋์ด ๊ฐ๋จํ๊ณ ์ข๋ค์ ๐