upload W3 - disk, nw, node, spicy#16
Open
su-lim wants to merge 2 commits intoW-CodeTest-Study:mainfrom
Open
Conversation
nohsion
reviewed
Feb 14, 2022
Comment on lines
+15
to
+19
| while(notK(scoville, K)): | ||
| answer+=1 | ||
| try: | ||
| scoville.append(scoville.pop(0) + (scoville.pop(0)*2)) | ||
| scoville.sort() |
Contributor
There was a problem hiding this comment.
반복문을 돌면서 pop(0)과 sort()를 매번 실행하는 것 때문에 효율성테스트에 통과되지 못하는거 같아요!
그래서 pop(0)대신 popleft가 가능한 queue를 쓰는 것이 좋은데, 여기서는 항상 가장 작은 값 두 개가 필요하니까 정렬을 시켜줘야 하잖아요? 이렇게 정렬된 상태의 큐를 쓸 때는 파이썬의 heapq를 이용하면 효율성도 잡을 수 있을 겁니닷!
heapq 참고: https://www.daleseo.com/python-heapq/
Comment on lines
+18
to
+22
| 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]) |
Contributor
There was a problem hiding this comment.
zip 사용은 볼때마다 놀랍네요.. 저는 enumerate 보고 신세계였는데 아직 배울게 많네요 ㅎㅎ
| shortest[node] = shortest[now] + 1 | ||
| queue += node | ||
|
|
||
| answer = shortest.count(max(shortest)) |
|
|
||
| def get_node_list(n, edge): | ||
|
|
||
| graph = [[] for i in range(n+1)] |
Contributor
There was a problem hiding this comment.
반복문에서 인덱스 i가 딱히 쓰이지 않는다면, 언더스코어(_)를 쓰는 게 좋다고 해요! (간지)
Comment on lines
+7
to
+10
| def recursive(p): | ||
| result = [] | ||
| global network | ||
| global visited |
Contributor
There was a problem hiding this comment.
경험 상.. bfs나 dfs 함수 만들 때, solution 함수 내에서 선언하면 global 없이도 사용가능한 것 같더라구요? 코테상에서는 이런 방법도 편하게 쓸 수 있을 것 같아서 알려드려요!
Contributor
There was a problem hiding this comment.
간단 예시
def solution():
network = []
visited = []
def recursive():
# network, visited 사용~
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.