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

[강희찬] WEEK 7 Solution #491

Merged
merged 5 commits into from
Sep 29, 2024
Merged

[강희찬] WEEK 7 Solution #491

merged 5 commits into from
Sep 29, 2024

Conversation

HC-kang
Copy link
Contributor

@HC-kang HC-kang commented Sep 23, 2024

답안 제출 문제

체크 리스트

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

@HC-kang HC-kang marked this pull request as ready for review September 25, 2024 00:09
@HC-kang HC-kang requested a review from a team as a code owner September 25, 2024 00:09

while (right < s.length) {
if (MAP.has(s[right])) {
left = Math.max(MAP.get(s[right])! + 1, left);
Copy link
Contributor

Choose a reason for hiding this comment

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

와, Map을 사용해서 인덱스를 저장하니, left 인덱스를 하나씩 증가시키지 않고 한 번에 점프할 수가 있네요. 한 수 배워 갑니다! 🙇

Comment on lines +59 to +69
for (let i = 1; i < r; i++) {
if (matrix[i][0] === 0) {
matrix[i].fill(0);
}
}

for (let j = 1; j < c; j++) {
if (matrix[0][j] === 0) {
matrix.forEach((row) => (row[j] = 0));
}
}
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.

넵 질문주셔서 감사합니다!

matrix의 가로, 세로 사이즈가 다를 수 있어서 분리 하였는데, 취향에 따라 아래와 같이 표현할 수는 있을 것 같습니다.

for (let i = 1; i < Math.max(r, c); i++) {
  if (matrix[i]?.[0] === 0) matrix[i].fill(0);
  if (matrix[0]?.[i] === 0) matrix.forEach((row) => (row[i] = 0));
}

다만 지극히 제 주관적으로, 위 코드는 전체 라인 수는 줄어들지만 조건이나 처리가 다소 지저분하다고 느껴져서 두 개의 순회로 분리하였습니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

아 네 희찬님, 제가 생각했던 코드는 요런 방식이었습니다!
이 방법이 가독성이 크게 떨어지지는 않는 것 같아서 소소하게 코멘트 남기려 했습니다!

Suggested change
for (let i = 1; i < r; i++) {
if (matrix[i][0] === 0) {
matrix[i].fill(0);
}
}
for (let j = 1; j < c; j++) {
if (matrix[0][j] === 0) {
matrix.forEach((row) => (row[j] = 0));
}
}
for (let i = 1; i < r; i++) {
for (let j = 1; j < c; j++) {
if (matrix[i][0] === 0 || matrix[0][j] === 0) {
matrix[i][j] = 0;
}
}
}

Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

수고하셨습니다.

@HC-kang HC-kang merged commit 7718d7b into DaleStudy:main Sep 29, 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