Skip to content

[WEEK01] 추슬기#2

Merged
doitchuu merged 6 commits intomainfrom
doitchuu
Feb 14, 2026
Merged

[WEEK01] 추슬기#2
doitchuu merged 6 commits intomainfrom
doitchuu

Conversation

@doitchuu
Copy link
Member

@doitchuu doitchuu commented Feb 11, 2026

이렇게 풀었어요

1. Two Sort

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

1) 복잡도 계산

  • 시간 복잡도: O(n²) → 이중 for문 사용
  • 공간 복잡도: O(1) → 별도 자료구조 사용 없음

2) 접근 아이디어

  1. 배열을 처음부터 순회한다.
  2. 현재 숫자와 그 다음 숫자들을 더해본다.
  3. 두 수의 합이 target과 같으면 해당 인덱스를 반환한다.

3) 회고

N제곱에서 N으로 줄이려면 Map을 사용하는 풀이도 있다. 해당 풀이로 디벨롭해도 좋을 듯합니다.



2. Valid Parentheses

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

1) 복잡도 계산

  • 시간 복잡도: O(n) → 문자열 한 번 순회
  • 공간 복잡도: O(n) → stack 배열 사용

2) 접근 아이디어

  1. 문자열을 순회한다.
  2. 여는 괄호는 stack에 넣는다.
  3. 닫는 괄호가 나오면 stack의 마지막 값과 비교한다.
  4. 짝이 맞으면 pop 한다.
  5. 마지막에 stack이 비어있으면 true

3) 회고

객체로 만들어 확인하는 방법도 직관적인 것 같습니다. 풀이방식을 항상 여러갈래로 고민해봐야 발전할 것 같아요.
아래 방식으로 푼 풀이도 좋은 것 같습니다!

function isValid(s: string): boolean {

    const bracketsMap = {
        ')': '(',
        ']': '[',
        '}': '{'
    }

    let openBracketsStack = []

    for (let i = 0; i < s.length; i++) {
        const currentBracket = s[i]

        if (['(', '[', '{'].includes(currentBracket)) {
            openBracketsStack.push(currentBracket)
        } else if (openBracketsStack.pop() !== bracketsMap[currentBracket]) {
            return false
        }
    }
    return !openBracketsStack.length
};


3. Merge Two Sorted List

  • 문제를 풀었어요.

1) 회고

링크드리스트 자료구조에 대한 이해와, 코드로 구현하는 능력이 부족했던 것 같습니다.
아래 풀이 방식보고, 정답이 잊혀지면 다시 풀어봐야할 것 같아요

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
var mergeTwoLists = function(list1, list2) {
  const dummy = new ListNode(0);
  let cur = dummy;

  while (list1 !== null && list2 !== null) {
    if (list1.val <= list2.val) {
      cur.next = list1;
      list1 = list1.next;
    } else {
      cur.next = list2;
      list2 = list2.next;
    }
    cur = cur.next;
  }

  // 남은 리스트를 그대로 붙이기
  cur.next = list1 !== null ? list1 : list2;

  return dummy.next;
};


4. Best Time To Buy And Sell Stock

  • 문제를 풀었어요.

1) 회고

해당 문제는 풀지 못해서, AI의 도움으로 접근법을 확인했습니다.
다른 분들 풀이 보면서 참고해서 다시 풀어보면 좋을 것 같습니다.



@github-actions github-actions bot requested review from raejun92 and sik9252 February 11, 2026 16:00
@doitchuu doitchuu changed the title [WEEK01] 추슬기 (작성중) [WEEK01] 추슬기 Feb 12, 2026
// MEMO: 시간 초과!
let maxPrice = 0;

for (let i = 0; i < prices.length - 1; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

시간 초과는 과거 최소값을 유지/갱신 하는 방향으로 코드를 수정하면 O(n)으로 줄일 수 있을 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 못 풀었는데ㅠ 팁을 알려주셔서 감사합니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

코드가 직관적이고 이해하기 쉽게 작성된 것 같아요 최고 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

if만 사용하면 각 조건을 모두 독립적으로 검사하게 되는 것으로 알고 있는데, 그렇기 때문에 아래와 같은 의도치 않은 비교가 발생할 수도 있을 것 같아요.

  1. 첫 번째 if에서 pop()이 실행
  2. 두 번째 조건도 if기 때문에 또 검사함
  3. 이때 이미 이전 조건에서 pop()이 일어나 stack[stack.length - 1] 값이 바뀐 상태임

그래서 이런식으로 if-elseif를 사용해서 작성하는게 조금 더 안전하지 않을까? 하는 생각을 해보았습니다!

if (ch === ")" && top === "(") stack.pop();
else if (ch === "}" && top === "{") stack.pop();
else if (ch === "]" && top === "[") stack.pop();

Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 같은 의견입니다!

Comment on lines +7 to +9
if (s.length % 2 !== 0) {
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 생각도 못했는데 예외 처리 좋네요

Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 같은 의견입니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

count는 어떤 용도로 사용하고 있는 걸까요?

// MEMO: 시간 초과!
let maxPrice = 0;

for (let i = 0; i < prices.length - 1; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 못 풀었는데ㅠ 팁을 알려주셔서 감사합니다.

@doitchuu doitchuu merged commit 021e082 into main Feb 14, 2026
1 check passed
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