-
-
Notifications
You must be signed in to change notification settings - Fork 195
[forest000014] Week 05 #851
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
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.
5문제 모두 푸시느라 수고 많으셨습니다! 승인하는데 영향이 없는 사소한 피드백 2개 남겼습니다.
if (prices[i] > max) { | ||
max = prices[i]; | ||
if (max - min > ans) { | ||
ans = max - min; | ||
} | ||
} | ||
if (prices[i] < min) { | ||
min = max = prices[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.
max
라는 변수가 없었으면 알고리즘이 더 간단할 수 있었겠다는 생각이 들었습니다.
if (prices[i] > max) { | |
max = prices[i]; | |
if (max - min > ans) { | |
ans = max - min; | |
} | |
} | |
if (prices[i] < min) { | |
min = max = prices[i]; | |
} | |
if (prices[i] - min > ans) { | |
ans = prices[i] - min; | |
} | |
if (prices[i] < min) { | |
min = prices[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.
다시 보니 굳이 불필요하게 max라는 변수를 쓸 필요가 없었네요... sweat_smile:
한번 사고의 흐름이 한 방향으로 생기고 나니, 코드를 간결하게 하려고 다시 봐도 잘 안 보이는 것 같네요 ㅠㅠ
List<List<String>> ans = new ArrayList<>(); | ||
for (String key : map.keySet()) { | ||
ans.add(new ArrayList<>()); | ||
for (String str : map.get(key)) { | ||
ans.get(ans.size() - 1).add(str); | ||
} | ||
} | ||
|
||
return ans; |
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.
이렇게 사소한 자료 구조 변환은 한 줄로 처리해주시면 위에 더 중요한 코드를 읽는데 더 집중할 수 있을 것 같아요.
List<List<String>> ans = new ArrayList<>(); | |
for (String key : map.keySet()) { | |
ans.add(new ArrayList<>()); | |
for (String str : map.get(key)) { | |
ans.get(ans.size() - 1).add(str); | |
} | |
} | |
return ans; | |
return new ArrayList<>(map.values()); |
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.
앗 이 부분은 map을 단순히 List로 바꾼 것은 아니고, 1-depth로 되어있는 map을 2-depth로 변환하기 위한 코드입니다
다시 보니 달레님께서 말씀해주신 게 그 기능이네요! 이런 식으로 할 수 있다는 걸 새롭게 배웠습니다 😄
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.