Conversation
raejun92
approved these changes
Apr 9, 2026
Comment on lines
+5
to
+11
| for (let i = 0; i < s.length; i++) { | ||
| if (stack.length === 0 || s[i] === "(") { | ||
| stack.push(s[i]); | ||
| } else { | ||
| stack.pop(); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
")"가 먼저 채워지는 조건에서는 얼리 리턴으로 처리해주면 좋을 것 같아요!
| let word = []; | ||
|
|
||
| s = s.split(" "); | ||
| s.map((e) => word.push(capitalize(e))); |
Collaborator
There was a problem hiding this comment.
map을 쓰셔서 뭔가 리턴하시려나보다 생각해서 변수를 빠뜨렷나 싶었어요ㅠ
forEach를 사용하면 오해가 없어질 것 같아요ㅎ
|
|
||
| s = s.split(" "); | ||
| s.map((e) => word.push(capitalize(e))); | ||
| answer = [...word].join(",").replaceAll(",", " "); |
Collaborator
There was a problem hiding this comment.
join에서 바로 (" ") 요거는 안되는 건가요?!
LeeBaeJin
approved these changes
Apr 9, 2026
doitchuu
approved these changes
Apr 9, 2026
| @@ -0,0 +1,14 @@ | |||
| function capitalize(str) { | |||
| return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); | |||
| } | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
이렇게 풀었어요
1. 최댓값과 최솟값
1) 복잡도 계산
시간 복잡도: O(n log n)
공간 복잡도: O(n)
2) 접근 아이디어
이 문제는 문자열로 주어진 숫자들을 공백 기준으로 나눈 뒤, 최솟값과 최댓값을 찾아 "최솟값 최댓값" 형태로 반환하는 문제이다. 배열로 만든 뒤 정렬해서 양 끝 값을 사용하면 쉽다.
2. JadenCase 문자열 만들기
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
이 문제는 문자열에서 각 단어의 첫 글자만 대문자로 바꾸고, 나머지는 소문자로 만들어 JadenCase 형태로 반환하는 문제이다.
capitalize라는 보조 함수를 만들어, 각 문자열에 대해 첫 글자는 대문자로, 나머지는 소문자로 변환하도록 했다. 이후 입력 문자열을 공백 기준으로 나누고, 각 단어에 capitalize를 적용한 뒤 다시 하나의 문자열로 합쳐 결과를 만들었다.
3. 올바른 괄호
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
이 문제는 문자열에 포함된 괄호가 올바르게 짝지어져 있는지 확인하는 문제이다. 괄호 문제는 가장 최근에 열린 괄호를 먼저 닫아야 하므로, 처음부터 스택을 사용하는 방식이 자연스럽게 떠올랐다.
그래서 문자열을 왼쪽부터 순회하면서 ( 이면 스택에 넣고, ) 이면 스택에서 하나를 꺼내는 방식으로 접근했다. 순회가 끝났을 때 스택이 비어 있으면 모든 괄호가 짝지어진 것이고, 비어 있지 않으면 올바르지 않은 괄호 문자열이라고 판단하도록 구현했다.