Merged
Conversation
JooKangsan
approved these changes
Mar 20, 2025
Collaborator
JooKangsan
left a comment
There was a problem hiding this comment.
많이 배우고 갑니다! 한주동안 수고하셨습니다!
Comment on lines
+5
to
+9
| const sorted = convertString.sort((a, b) => { | ||
| const AB = Number(a + b) | ||
| const BA = Number(b + a) | ||
| return BA - AB | ||
| }) |
Collaborator
There was a problem hiding this comment.
이부분은 숫자로 변경하지 않고 문자열 비교 후 반환 해도 괜찮을 것 같아요!!
const sorted = convertString.sort((a, b) => (b + a) > (a + b) ? 1 : -1)
Collaborator
There was a problem hiding this comment.
코드 잘 보았습니다!
selected 배열 대신 선택된 값의 누적합을 실시간으로 처리하고, sum을 매개변수로 넘긴 뒤 depth가 3일 때만 비교하는 방식은 어떨까요?
이렇게 하면 인덱스를 배열에 저장하고 다시 값을 꺼내는 과정을 생략할 수 있고, 매번 for문으로 합을 구하지 않아도 돼요!
const solution = (number) => {
let result = 0
const dfs = (depth, start, sum) => {
if (depth === 3) {
if (sum === 0) result++
return
}
for (let i = start; i < number.length; i++) {
dfs(depth + 1, i + 1, sum + number[i])
}
}
dfs(0, 0, 0)
return result
}
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.
📌 푼 문제
📝 간단한 풀이 과정
두 개 뽑아서 더하기
삼총사
가장 큰 수
H-Index
파일명 정렬