-
Notifications
You must be signed in to change notification settings - Fork 1
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
7-fnzksxl #30
Conversation
q = deque(people) | ||
while q: | ||
heavy = q.pop() | ||
if len(q) and heavy+q[0] <= limit: | ||
q.popleft() | ||
|
||
answer+=1 |
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.
์คํธ ์ ๋ ํ์ด๋ฅผ ์๋ณด๊ณ ์ฐ์ ํ์ด๋ดค๋๋ฐ ์๊ฐํ ์์ด๋์ด๋ ๋๊ฐ๊ตฐ์!!
์ ๋ ๋ฑ ์ฐ๋ ๋์ ์ ์ด์งํผ ๋ฌธ์ ์ 2๋ช ์ฉ ๋ฐ์ ์๋๋ค๊ณ ํด์ start์ end๋ณ์๋ฅผ ์ฌ์ฉํด์ ํ์์ต๋๋ค!!
def solution(people, limit):
people.sort()
start = 0
end = len(people) -1
answer = 0
while(start<=end):
if(people[start]+people[end] <= limit):
start += 1
end-=1
answer +=1
return answer
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.
์ค, ๋ฆฌ์คํธ์ ์๋จ์์๋ถํฐ ๋ด๋ ค์ค๋ ๋ฐฉ์์ด๊ตฐ์. ์ด๊ฒ ์ข ๋ ๊น๋ํ ํ์ด ๊ฐ์ต๋๋ค.. ใ ใ ใ ใ
์ด ์ฌ๋ ๊ธ์ ์์ด๋ค... |
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.
์ค๋ช ์ ๋ณด๊ณ ํผ์ ๋ค์ ๋ฌธ์ ๋ฅผ ํ์ด๋ดค๋๋ฐ ์ ์๊พธ index out of range ๊ฐ ๋จ์ง... ํ๋ค๊ฐ 2๋ฒ์งธ ํ ์คํธ ์ผ์ด์ค์์ deque ์์ ๋ชจ๋ ์์๊ฐ ๋น ์ ธ ๋๊ฐ ์๋ ์๋ค๋ ๊ฒ์ ๊นจ๋ฌ์๋ค์ ใ ใ ใ
from collections import deque
def solution(people, limit):
answer = 0
people.sort()
deq = deque(people)
while deq :
heavyPeople = deq.pop()
if len(deq) !=0 and heavyPeople + deq[0] <= limit :
deq.popleft()
answer += 1
return answer
@tgyuuAn ํฐ์นํ.. ์ด๋๊น์ ใ ใ ใ ใ |
@wkdghdwns199 ๋น ๋ค ๋น ์ ธ๋๊ฐ๋ฉด ๋น ๋ฆฌ์คํธ๋ผ ์ฝ๋๊ฐ ํฐ์ง๋๋ค.! ๊ทธ๋ฐ๋ฐ if len(q) != 0 and ~~: ์ด๋ ๊ฒ ์์ฑํ์๋ฉด ๋ถํ์ํ ํ์ด์ค๋ธ์ ํธ๊ฐ ์๊ฒจ์ ๋น๊ตํ๋ ํํ๋ก if๋ฌธ ์กฐ๊ฑด์ ํ์ธํ๊ฒ ๋๋๋ฐ์. |
๐ ๋ฌธ์ ๋งํฌ
๊ตฌ๋ช ๋ณดํธ
โ๏ธ ์์๋ ์๊ฐ
30๋ถ
โจ ์๋ ์ฝ๋
์์ด๋์ด๋ ๋งค์ฐ ๊ฐ.๋จํฉ๋๋ค.
ํ์ฌ people ๋ฆฌ์คํธ์์ ๊ฐ์ฅ ๊ฐ๋ฒผ์ด ์ฌ๋ + ๊ฐ์ฅ ๋ฌด๊ฑฐ์ด ์ฌ๋์ด limit๋ณด๋ค ๋ฌด๊ฑฐ์ด๊ฐ? ์๋๊ฐ?๋ง
๊ตฌ๋ถํ ์ ์๋ค๋ฉด ๋ ๋ช ์ ํ์์ผํ ์ง ํ ๋ช ๋ง ํ์์ผํ ์ง ์ ์ ์๊ฒ ์ฃ ?
์ด๋ฅผ ์ํด์ ๋จผ์ ์ค๋ฆ์ฐจ์์ผ๋ก people ๋ฆฌ์คํธ๋ฅผ ์ ๋ ฌํด์ค ๋ค, ๊ฐ์ฅ ์๊ณผ ๋ค๋ฅผ ๋ํด limit์ ๋น๊ตํด์ค๋๋ค.
๊ฐ์ฅ ๊ฐ๋ฒผ์ด ์ฌ๋ + ๊ฐ์ฅ ๋ฌด๊ฑฐ์ด ์ฌ๋ > limit
๊ฐ์ฅ ๊ฐ๋ฒผ์ด ์ฌ๋ + ๊ฐ์ฅ ๋ฌด๊ฑฐ์ด ์ฌ๋ <= limit
์ด๋ฅผ people ๋ฆฌ์คํธ์ ๊ธธ์ด๊ฐ 0์ด ๋ ๋๊น์ง ๋ฐ๋ณตํด์ค์๋ค.
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
๊ทธ๋ฆฌ๋ ๋ฌธ์ ๋ ์์ ์ ์ ์ ๋ ฌ์ ์์ฃผ ํ๊ฒ ๋๋ ๊ฒ ๊ฐ์ ๋๋์ ๋๋ค.