[mingxoxo] programmers_타겟 넘버_Python - #38
Open
mingxoxo wants to merge 3 commits into
Open
Conversation
mingxoxo
requested review from
jaejunmin408,
just-stopyoon,
sangkyu39 and
seungbinpark
March 2, 2025 13:55
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.
🔗 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/43165
💡 풀이 아이디어
타겟 넘버를 만족하는 식을 만들기 위해서 모든 경우의 수를 확인해보아야 할 것이라는 점에서 Brute Force 같기도 해서 재귀를 이용해서 DFS로 풀이하였습니다.
오랜만에 재귀 함수를 사용하려고 하니 머리가 잘 안 돌아가더라구요..!
처음에는 아래처럼 값을 저장하는 ans 변수를 사용했는데, GPT에게 물어보아 조금 더 깔끔하게 ans 변수를 사용하지 않고 바로 반환 값으로 정답을 활용하였습니다.
📝 새로 학습한 내용
다른 사람의 풀이 중 리스트 슬라이싱을 활용한 방법이 있었는데, 이렇게 되면 계속 객체 배열을 생성해야 하기 때문에 메모리가 비효율적일 것 같아 인덱스를 활용하였습니다. 케이스마다 다르겠지만 시간은 아래 코드가 제 코드보다 빨랐고 메모리는 대부분 아주 미세한 차이로 제 코드가 적게 사용하였습니다. 파이썬이 자체적으로 효율적으로 처리하는 것이 있어서 시간이 차이가 나는 것인가 싶은데 아직도 어려운 것 같습니다.. 😂
📚 참고 자료