Skip to content
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

Merged
merged 7 commits into from
Sep 21, 2024
Merged

[kayden] Week 06 Solutions #477

merged 7 commits into from
Sep 21, 2024

Conversation

kjb512
Copy link
Contributor

@kjb512 kjb512 commented Sep 20, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@kjb512 kjb512 added the py label Sep 20, 2024
@kjb512 kjb512 self-assigned this Sep 20, 2024
@kjb512 kjb512 changed the title Valid Parentheses Solution [kayden] Week 06 Solutions Sep 20, 2024
@kjb512 kjb512 marked this pull request as ready for review September 20, 2024 14:42
@kjb512 kjb512 requested a review from a team as a code owner September 20, 2024 14:42
Comment on lines +5 to +6
if len(s) % 2 != 0:
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

이 생각 못했네요!

Comment on lines +14 to +32
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
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 재귀함수를 사용하신 이유가 있을까요? :)

저는 반복문으로 구현하는 것이 공간 사용 측면에서는 더 효율적일 것 같다는 생각을 했습니다

왜냐하면 위처럼 재귀함수를 사용할 경우 마지막 좌표에 도달할 때까지 재귀함수의 호출 스택만큼의 추가적인 공간을 사용하게 될 것 같거든요

Copy link
Contributor Author

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라고 틀에박힌 생각을 했네요.

Copy link
Contributor

@Sunjae95 Sunjae95 left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

bisect_left로 정답배열에 들어갈 위치를 지정할 수 있군요..!
리스트에서 num값이 들어갈 위치를 찾는 방법을 적용하는 아이디어는 참신한 아이디어 같아요 👍

@kjb512 kjb512 merged commit c57beac into DaleStudy:main Sep 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants