-
Notifications
You must be signed in to change notification settings - Fork 26
초급반 / 이지우 / 블랙잭 - 2798, N과M_6 - 15655, 제곱수찾기 - 1025 #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전반적인 구조는 아주 깔끔하고 잘 구성되어 있습니다!
그러나 문제의 핵심 조건 중 하나인 중복 수열 제거가 누락되어 있기 때문에 이걸 보완해야 완전한 풀이라고 생각합니다.
CS 지식 기반으로 보면 시간/공간 복잡도 측면에서는 좋은 코드 같습니다.
import java.util.*; | ||
|
||
public class Main { | ||
static int N, M; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀에서 사용될 변수는 전역으로 선언해 코드를 간결화하셨는데, 이 방식은 성능상 큰 문제는 없지만, 함수 인지로 전달하는 방식이 테스트 용이성엔 더 좋기에 전역 변수 사용을 지양하고 되도록이면 함수 인자로 사용하는 게 좋을 것 같습니다.
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
arr = new int[N]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정해진 크기만큼만 할당해 메모리 낭비 없는 점 좋습니다.
System.out.print(sb); | ||
} | ||
|
||
static void solve(int start, int depth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solve() 함수명보다 generateCombinations() 또는 dfs()가 의미 전달에 명확하기 때문에 네이밍을 변경하는 게 좋아 보입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N과M 문제에서는 출력할 때 메모리 낭비를 막기 위해 StringBuilder를 사용하셨는데, 이 코드에서는 사용하지 않은 점이 아쉽습니다.
또한 변수명이 추상적이기 때문에,(N, M, max) 실무에서는 의미 전달이 명확한 이름을 사용할 수 있도록 지금부터라도 네이밍에 신경 써 보는 것도 좋을 것 같습니다. (N → numCards, M → targetSum, max → maxSum 등)
cards[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
for (int i = 0; i < N - 2; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확장성과 테스트를 고려하면 로직을 함수로 분리하는 것도 고려해 볼 만하다고 생각합니다.
No description provided.