Skip to content

[WEEK09] 추슬기#43

Merged
doitchuu merged 3 commits into
pnt-fe-study:mainfrom
doitchuu:doitchuu
Apr 9, 2026
Merged

[WEEK09] 추슬기#43
doitchuu merged 3 commits into
pnt-fe-study:mainfrom
doitchuu:doitchuu

Conversation

@doitchuu
Copy link
Copy Markdown
Member

@doitchuu doitchuu commented Apr 8, 2026

이렇게 풀었어요

1. 최댓값과 최솟값

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

1) 복잡도 계산

  • 시간 복잡도: O(n log n)
  • 공간 복잡도: O(n)

2) 접근 아이디어

  1. 문자열을 공백 기준으로 나눠 숫자 배열로 만들었다.
  2. 숫자 기준으로 정렬해서 맨 앞과 맨 뒤 값을 확인했다.
  3. 최솟값과 최댓값을 이어서 문자열로 반환했다.

3) 회고

function solution(s) {
    const arr = s.split(" ").map(Number);
    
    let min = arr[0];
    let max = arr[0];

    for (let num of arr) {
        if (num < min) min = num;
        if (num > max) max = num;
    }

    return min + " " + max;
}

해당 방식이 for문 한번만 돌면 되니 더 풀이가 좋은 것 같다.



2. JadenCase 문자열 만들기

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

1) 복잡도 계산

  • 시간 복잡도: O(n)
  • 공간 복잡도: O(n)

2) 접근 아이디어

  1. 문자열을 공백 기준으로 나눠 단어별로 처리했다.
  2. 각 단어의 첫 글자는 대문자로, 나머지는 소문자로 바꿨다.
  3. 빈 문자열은 그대로 두고 다시 공백으로 합쳤다.

3) 회고

다들 비슷하게 푼 것 같아서, 따로 회고를 진행하지 않았다.

for문이냐 메서드냐의 차이라 map으로 적용했다.



3. 올바른 괄호

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

1) 복잡도 계산

  • 시간 복잡도: O(n)
  • 공간 복잡도: O(n)

2) 접근 아이디어

  1. 먼저 스택으로 괄호 짝을 맞추는 방식으로 접근했다.
  2. 이후 괄호 종류가 하나뿐이라는 점을 보고 카운트 방식으로도 다시 풀어봤다.
  3. 순회 중 음수가 되면 바로 false, 끝났을 때 0이면 올바른 괄호라고 판단했다.

3) 회고

function solution(s){
    if (s[0] === ")") {
        return false;
    }

    let result = 0;
    
    for (let i = 0; i < s.length; i++) {
        if (s[i] === "(") {
            result++;
        } else {
            result--;
        }
        
        if (result < 0) {
            return false;
        }
    }
    
    return result === 0;
}

처음에는 바로 스택이 떠올라서 스택으로 풀었는데 괄호 종류가 하나다보니 변수를 하나 선언해서 카운트를 하거나 표기해줘도 괜찮겠다는 생각이 들어 다시 풀어보았다. 배열에 값추가보다는 카운트 방식이 이번 문제에서는 더 적절했을 것 같다.



@doitchuu doitchuu self-assigned this Apr 8, 2026
Copy link
Copy Markdown
Collaborator

@raejun92 raejun92 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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

메서드 활용이 깔끔하네요!

Comment on lines +8 to +14
for (let i = 0; i < s.length; i++) {
if (s[i] === "(") {
stack.push("(");
} else {
stack.pop();
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

")"가 먼저 채워지는 조건에서는 얼리 리턴으로 처리해주면 좋을 것 같아요!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

깔끔하네요!

Copy link
Copy Markdown
Collaborator

@LeeBaeJin LeeBaeJin left a comment

Choose a reason for hiding this comment

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

확실히 내장 함수 사용에 있어서는 Java보단 Javascript가 더 깔끔합니다!

수고많으셨습니다!

Copy link
Copy Markdown
Collaborator

@sik9252 sik9252 left a comment

Choose a reason for hiding this comment

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

전체적으로 깔끔해서 좋은 것 같습니다

@doitchuu doitchuu merged commit 832e553 into pnt-fe-study:main Apr 9, 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.

4 participants