Merged
Conversation
JooKangsan
approved these changes
Jan 16, 2025
Collaborator
There was a problem hiding this comment.
이거 sort 메서드를 사용한 이유가 있나요....?
문제는 기존의 숫자들을 뒤집어라 인데 이렇게 하면 뒤집은게 아니라 그냥 정렬한거같아서요...
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.
📌 푼 문제
📝 간단한 풀이 과정
문자열뒤집기
주어진 문자열을 배열로 변환하여 각 문자를 저장한 뒤, sort 메서드를 사용해 알파벳 순으로 정렬
컨트롤 제트
문자열 s를 공백(" ") 기준으로 나누어 각 요소를 순회합니다.
"Z"가 나오면 마지막에 추가된 숫자를 stack에서 제거합니다(pop).
숫자가 나오면 해당 숫자를 stack에 추가합니다(push).
모든 작업이 끝난 뒤, stack에 남아있는 숫자들을 합산(reduce)하여 결과를 반환합니다.
만약 stack이 비어있다면, 결과는 0을 반환합니다.
영어가 싫어요
숫자를 나타내는 영어 단어(zero부터 nine)를 배열로 저장합니다.
forEach를 활용하여 주어진 문자열에서 해당 영어 단어를 숫자로 대체합니다.
각 영어 단어를 기준으로 split하여 문자열을 나눈 뒤, join으로 숫자(index)로 대체합니다.
변환이 끝난 문자열을 Number로 변환하여 최종 결과를 반환합니다.
문자열 계산하기
문자열을 공백(" ") 기준으로 나누어 각 요소를 배열(splited)로 저장합니다.
첫 번째 숫자를 초기값으로 설정합니다(ans).
forEach를 활용하여 배열을 순회하면서, 현재 요소가 "+" 또는 "-"일 경우 다음 숫자를 더하거나 빼는 방식으로 연산을 진행합니다.
최종적으로 계산된 값을 반환합니다.
크레인 인형 뽑기 게임
board 배열과 moves 배열을 이용해 크레인 동작을 시뮬레이션합니다.
moves 배열을 순회하면서 각 동작의 열(column)을 확인합니다.
해당 열에서 가장 위에 있는 인형을 stack에 추가합니다.
만약 stack의 마지막 두 개 인형이 같다면, 터뜨리고(pop) 점수(count)를 증가시킵니다.
인형을 옮긴 자리는 0으로 설정해 비워줍니다.
최종적으로 터뜨린 인형의 개수(count)를 반환합니다.