-
Notifications
You must be signed in to change notification settings - Fork 6
upload W3 - disk, nw, node, spicy #16
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
base: main
Are you sure you want to change the base?
Conversation
| while(notK(scoville, K)): | ||
| answer+=1 | ||
| try: | ||
| scoville.append(scoville.pop(0) + (scoville.pop(0)*2)) | ||
| scoville.sort() |
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.
반복문을 돌면서 pop(0)과 sort()를 매번 실행하는 것 때문에 효율성테스트에 통과되지 못하는거 같아요!
그래서 pop(0)대신 popleft가 가능한 queue를 쓰는 것이 좋은데, 여기서는 항상 가장 작은 값 두 개가 필요하니까 정렬을 시켜줘야 하잖아요? 이렇게 정렬된 상태의 큐를 쓸 때는 파이썬의 heapq를 이용하면 효율성도 잡을 수 있을 겁니닷!
heapq 참고: https://www.daleseo.com/python-heapq/
| for job, i in zip(jobs[idx:], range(idx,len(jobs))): | ||
| if job[0] > current: # 작업의 요청시간이 현재보다 클 경우 | ||
| break | ||
| if i not in finish: | ||
| vaild.append(job + [i]) |
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.
zip 사용은 볼때마다 놀랍네요.. 저는 enumerate 보고 신세계였는데 아직 배울게 많네요 ㅎㅎ
| shortest[node] = shortest[now] + 1 | ||
| queue += node | ||
|
|
||
| answer = shortest.count(max(shortest)) |
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.
한 줄로.. good입니당!
|
|
||
| def get_node_list(n, edge): | ||
|
|
||
| graph = [[] for i in range(n+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.
반복문에서 인덱스 i가 딱히 쓰이지 않는다면, 언더스코어(_)를 쓰는 게 좋다고 해요! (간지)
| def recursive(p): | ||
| result = [] | ||
| global network | ||
| global visited |
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.
경험 상.. bfs나 dfs 함수 만들 때, solution 함수 내에서 선언하면 global 없이도 사용가능한 것 같더라구요? 코테상에서는 이런 방법도 편하게 쓸 수 있을 것 같아서 알려드려요!
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.
간단 예시
def solution():
network = []
visited = []
def recursive():
# network, visited 사용~
No description provided.