Skip to content

[이예슬] 3주차 문제풀이#16

Open
mimpie wants to merge 1 commit intomainfrom
lys
Open

[이예슬] 3주차 문제풀이#16
mimpie wants to merge 1 commit intomainfrom
lys

Conversation

@mimpie
Copy link
Contributor

@mimpie mimpie commented Nov 17, 2023

🖊️ 해결과정 기록

1️⃣ [1차]프렌즈 4블록 (2h)

💭 어떻게 접근했나요?

  • 배열의 문자열을 2차원 배열로 나눈다.
  • 배열에서 제거될 블록의 인덱스를 구해 removedBlocks안에 넣는다.
  • 배열에서 제거될 블록을 0으로.
  • 제거된 블록을 없애고 위에서 블록을 당겨온다. (이 때 먼저 위에서 가져올 블록이 있는지 검사)

2️⃣ 스택 수열(1h)

💭 어떻게 접근했나요?

  • 현재 순회 중인 수(targetNum)가 스택의 맨 위에 있는 수보다 크거나 같을 때까지 반복한다.
  • 이때, 스택에 순차적으로 1부터 targetNum까지의 수를 push하고, + 를 answerStack에 추가.
  • 스택에서 pop을 하고 이에 해당하는 - 를 answerStack에 추가.
  • 만약 스택에서 pop한 값과 targetNum가 일치하지 않으면, 수열이 안 만들어진다.

🎸 기타 추가사항

@mimpie mimpie self-assigned this Nov 17, 2023
Copy link

@Cha-Ji Cha-Ji left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

Copy link

Choose a reason for hiding this comment

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

+, -, NO 같은 문자도 상수로 관리해도 좋을 것 같습니다.
#9 (comment)

Comment on lines +28 to +46
Copy link

Choose a reason for hiding this comment

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

당장 수정할 수 있는 부분은 아니라고 생각되지만, 들여쓰기는 적을수록 좋습니다.
시간복잡도가 예측이 안되고 가독성이 떨어지기 때문입니다.
그래도 로직이 복잡하면 어쩔 수 없죠. 그냥 고민한번 해보세요.
클린코드에도 작게 만들라는 이야기가 있던것같네요.

Copy link
Contributor

@mjj111 mjj111 left a comment

Choose a reason for hiding this comment

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

너무 고생하셨습니다 👍

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

Choose a reason for hiding this comment

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

들여쓰기가 깊어질 수록
상위에 선언된 명령을 모두 기억해야 하위 코드를 이해할 수 있게 되기 때문에,
하위 코드를 이해하기 위한 부담이 커집니다..!
코테에서 빠른 시간안에 문제를 푸는 것도 중요하지만,
함수로 쪼개서 구현하는 것도 디버깅에 매우 유용해서
쪼개서 구현하는게 추후에 더 좋을 것 같습니다!

Copy link
Collaborator

@hwinkr hwinkr left a comment

Choose a reason for hiding this comment

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

자바스크립트로 푸는 분을 만나서 반갑네요 :)
고생하셨습니다

Comment on lines +13 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

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

자바스크립트 Array.prototype.every를 적용해보면 더 깔끔하고 선언적인 코드를 만들 수 있을 것 같습니다 :)

Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

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

개인적으로 자바스크립트로 알고리즘 문제를 풀 때도 let사용을 지양하려고 하는데요, let을 사용하다보면 같은 스코프 내부라면 어디서든 수정이 가능하므로 문제를 틀렸을 때 디버깅하기가 힘들어진다고 생각하기 때문입니다. 함수를 추가로 만들고 그 함수의 반환값을 const로 선언해서 필요할 때만 사용해보는 것도 좋을 것 같습니다.
예를 들어, 이 문제에서 구해야 하는 값이 총 파괴된 블럭의 수이므로

if (removedBlocks.length === 0) break;

if (removedBlocks.length === 0) return 파괴된블럭의수를센다(Board);

로 변경하면 totalRemoved 변수를 사용하지 않을 수 있습니다.
const를 사용해서 더 선언적으로 코드를 작성하는 것을 알고리즘 문제 풀이를 통해서 학습해보기 좋다고 생각합니다.
추가로 절차와 선언의 차이를 학습해보셔도 좋을 것 같네요:)

Copy link
Collaborator

@hwinkr hwinkr left a comment

Choose a reason for hiding this comment

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

자바스크립트로 푸는 분을 만나서 반갑네요 :)
고생하셨습니다

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.

4 participants