-
Notifications
You must be signed in to change notification settings - Fork 126
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
[kayden] Week 06 Solutions #477
Conversation
if len(s) % 2 != 0: | ||
return False |
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 dfs(x, y, direction): | ||
answer.append(matrix[x][y]) | ||
nx = x + dx[direction] | ||
ny = y + dy[direction] | ||
|
||
|
||
if 0 <= nx < m and 0 <= ny < n and not visited[nx][ny]: | ||
visited[nx][ny] = True | ||
return dfs(nx, ny, direction) | ||
|
||
direction = (direction+1) % 4 | ||
nx = x + dx[direction] | ||
ny = y + dy[direction] | ||
|
||
if 0 <= nx < m and 0 <= ny < n and not visited[nx][ny]: | ||
visited[nx][ny] = True | ||
return dfs(nx, ny, direction) | ||
else: | ||
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.
그래프 탐색이라서 DFS, BFS 라고 생각하고 문제가 한쪽 방향으로 탐색하길래 DFS를 사용하는게 직관적으로 편하다고 생각을 했는데 다시 보니 틀에 박힌 생각이였네요. 단순 반복문을 사용해서 하는게 더 효율적이네요!
좋은 답변 감사합니다! 그래프 탐색은 DFS, BFS라고 틀에박힌 생각을 했네요.
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.
안녕하세요 kayden님!
금주 모든 풀이하느랴 고생많으셨습니다.
path = [] | ||
|
||
for num in nums: | ||
idx = bisect_left(path, num) |
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.
bisect_left로 정답배열에 들어갈 위치를 지정할 수 있군요..!
리스트에서 num값이 들어갈 위치를 찾는 방법을 적용하는 아이디어는 참신한 아이디어 같아요 👍
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.