Skip to content

[WEEK02] 최준호#5

Merged
raejun92 merged 3 commits intomainfrom
raejun
Feb 22, 2026
Merged

[WEEK02] 최준호#5
raejun92 merged 3 commits intomainfrom
raejun

Conversation

@raejun92
Copy link
Collaborator

@raejun92 raejun92 commented Feb 19, 2026

이렇게 풀었어요

1. Valid Palindrome

  • 문제를 풀었어요.
  • 풀이 시간 : 20분

1) 복잡도 계산

시간 복잡도: O(n)


2) 접근 아이디어

  1. 문자열을 소문자로 변환한다.
  2. 알파벳과 숫자만 남기고 모두 제거한다.
  3. 양 끝에서부터 하나씩 비교해가며 팰린드롬인지 확인한다.

3) 회고

평소 정규표현식에 대한 지식이 있다면 더 간단하게 풀이할 수 있었을 것 같다.
메서드가 익숙지 않아 시간이 다소 걸렸지만, 풀이 자체는 어렵지 않았다.



2. Valid Anagram

  • 문제를 풀었어요.
  • 풀이 시간 : 4분

1) 복잡도 계산

시간 복잡도: O(nlogn) — 정렬 사용


2) 접근 아이디어

  1. 문자열을 문자 단위로 나눈다.
  2. 알파벳 순서대로 정렬한다.
  3. 다시 문자열로 합쳐서 두 문자열이 같은지 비교한다.

3) 회고

정렬을 이용한 간단한 풀이로 빠르게 해결했다.



3. Binary Search

  • 문제를 풀었어요.
  • 풀이 시간 : 20분

1) 복잡도 계산

시간 복잡도: O(logn)


2) 접근 아이디어

  1. 배열의 시작과 끝 인덱스를 설정한다.
  2. 중간값을 구해 target과 비교한다.
  3. 중간값이 target보다 크면 끝 인덱스를 mid - 1로, 작으면 시작 인덱스를 mid + 1로 갱신한다.
  4. target을 찾으면 해당 인덱스를 반환하고, 찾지 못하면 -1을 반환한다.

3) 회고

처음에 양 끝에서부터 하나씩 비교해가며 target과 같은 값이 있는지 확인하는 방식으로 풀이했는데, 시간 복잡도가 O(n)이어서 이진 탐색 알고리즘을 이용하여 다시 풀이했다.



4. Invert Binary Tree

  • 문제를 풀었어요.
  • 풀이 시간 : 43분

1) 복잡도 계산

시간 복잡도: O(n)


2) 접근 아이디어

  1. 재귀적으로 트리를 탐색한다.
  2. 각 노드에서 왼쪽과 오른쪽 자식 노드를 바꿔준다.
  3. 왼쪽, 오른쪽 서브트리에 대해 같은 작업을 반복한다.

3) 회고

재귀가 익숙하지 않아 풀이하는 데 시간이 다소 걸렸다.
완전 이진트리와 이진트리 개념이 헷갈려서 풀이하는 데 시간이 더 걸렸던 것 같다.



5. Flood Fill

  • 문제를 풀었어요.
  • 풀이 시간 : -

1) 복잡도 계산

시간 복잡도: O(n) — 모든 픽셀을 최대 한 번 방문


2) 접근 아이디어

  1. BFS 알고리즘을 이용하여 시작 픽셀부터 탐색한다.
  2. 상하좌우 인접 픽셀이 원래 색상과 같으면 새 색상으로 변경하고 큐에 추가한다.
  3. 큐가 빌 때까지 반복한다.

3) 회고

BFS를 이용해서 문제를 풀려고 했다.
2차원 배열의 row와 col이 다소 헷갈렸고 반복문의 조건 설정이 어려웠다.
if문의 예외 처리를 생각하지 못하여 풀이를 완료하지 못하였다.
다른 사람들의 풀이를 보니 DFS로 푼 것이 공간 및 시간 복잡도 측면에서 더 효율적으로 나왔다. 왜 그런 걸까?



@github-actions github-actions bot requested review from doitchuu and sik9252 February 19, 2026 14:03
@raejun92 raejun92 changed the title feat(raejun): 1~3주차 알고리즘 풀이 [WEEK02] 최준호 Feb 19, 2026
Comment on lines +33 to +34
if (nums[start] === target) return start;
if (nums[end] === target) return end;
Copy link
Collaborator

Choose a reason for hiding this comment

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

시간 복잡에는 문제가 없는거 같지만, 왜 이 비교(매 루프마다 양 끝 비교하는 부분)가 필요한지의 관점에서 보면 mid 비교만 남긴다면 더 단순해질 것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그렇네요 반복문 전에 한 번 확인하고 반복문에서는 mid만 확인하면 될 것 같아요!

*/
var floodFill = function (image, sr, sc, color) {
const queue = [[sr, sc]];
let cur = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 shift() 말고 바로 포인터 방식 떠올리셨나요? 대박

* @return {TreeNode}
*/
var invertTree = function (root) {
function change(root) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

change 재정의 안하고 invertTree 자체를 재귀로 돌려도 좋을 것 같슴다! 저도 재귀 넘 어려워요ㅠ

var isAnagram = function (s, t) {
s = s
.split("")
.sort((a, b) => a.charCodeAt() - b.charCodeAt())
Copy link
Member

Choose a reason for hiding this comment

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

charCodeAt 메서드로도 풀 수 있군요..!
메서드체이닝으로 코드가 간단해져서 풀이가 잘 보이네요 👍

(s) =>
(48 <= s.charCodeAt() && s.charCodeAt() <= 57) ||
(97 <= s.charCodeAt() && s.charCodeAt() <= 122),
);
Copy link
Member

Choose a reason for hiding this comment

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

메서드를 잘 쓰시는군요 👍

if문의 예외 처리를 생각하지 못하여 풀이를 하지 못하였다.
다른 사람들의 풀이를 보니 DFS로 푼 것이 공간 및 시간 복잡도 측면에서 더 효율적으로 나왔다.
왜 그런 걸까?
*/
Copy link
Member

Choose a reason for hiding this comment

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

저도 다른 사람 풀이를 보긴 했는데,
BFS로 푼 방식도 좋은 풀이인 것 같습니다 👍
shift 메서드를 쓰시지 않아서 더 좋은 것 같아욥

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shift를 쓰지않고 BFS로 풀어도 DFS가 더 좋게 나오더라구요!

@raejun92 raejun92 merged commit 0d8c9f1 into main Feb 22, 2026
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.

3 participants