-
-
Notifications
You must be signed in to change notification settings - Fork 247
[std-freejia] week 02 solutions #1753
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
안녕하세요 @hj4645 님! 리뷰 부탁드려도 될까요 😀 |
안녕하세요 스터디 리더 @TonyKim9401 님! 😀 혹시 리뷰 부탁드려도 될까요? 감사합니다. |
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.
저도 요 문제(climbing stairs) 비슷하게 풀었는데, 리트코드 풀이들 보다보니 공간 복잡도를 줄이기 위해 배열 대신 마지막 두 값을 저장하는 변수를 사용하는 방법도 있더라구요!
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.
이 문제는 맵을 하나만 선언해서 count를 빼주는 방식으로 풀었었는데, 2개를 선언해서 equals로 푸는 방법도 가독성 면에서 좋은 것 같습니다
2주차도 수고 많으셨습니다!😆
리뷰가 늦어 죄송합니다🥲
Map<Character, Integer> map = new HashMap<>();
// s의 문자로 카운트 증가
for (char c : s.toCharArray()) {
map.put(c, map.getOrDefault(c, 0) + 1);
}
// t의 문자로 카운트 감소
for (char c : t.toCharArray()) {
int count = map.getOrDefault(c, 0);
if (count == 0) { // t에만 있는 문자가 있거나, 같은 문자가 더 많으면
return false;
}
map.put(c, count - 1);
}
return true;
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!