Skip to content

Conversation

@su-lim
Copy link
Contributor

@su-lim su-lim commented Feb 11, 2022

No description provided.

Comment on lines +15 to +19
while(notK(scoville, K)):
answer+=1
try:
scoville.append(scoville.pop(0) + (scoville.pop(0)*2))
scoville.sort()
Copy link
Contributor

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/

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])
Copy link
Contributor

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))
Copy link
Contributor

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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반복문에서 인덱스 i가 딱히 쓰이지 않는다면, 언더스코어(_)를 쓰는 게 좋다고 해요! (간지)

Comment on lines +7 to +10
def recursive(p):
result = []
global network
global visited
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

경험 상.. bfs나 dfs 함수 만들 때, solution 함수 내에서 선언하면 global 없이도 사용가능한 것 같더라구요? 코테상에서는 이런 방법도 편하게 쓸 수 있을 것 같아서 알려드려요!

Copy link
Contributor

@nohsion nohsion Feb 14, 2022

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 사용~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants