7주차 알고리즘 문제 풀이(1) - 송헌욱 - #32
Merged
Merged
Conversation
juneheel
reviewed
Aug 11, 2024
|
|
||
| public static String solution(int N, String[] words) { | ||
| StringBuilder result = new StringBuilder(); | ||
| Set<String> uniqueWords = new HashSet<>(List.of(words)); |
Contributor
There was a problem hiding this comment.
중복제거를 Set을 이용해하셨네요! 이문제에서는 왜 생각을 못했는지,, 그리고 Set에서 배열을 List.of()로 바로생성해주는것을 알게되었어요👍
Member
Author
There was a problem hiding this comment.
네! String 배열을 하나하나 확인하기 보다는 그냥 Set으로 바로 처리했어요! 새로운 걸 알게 되셨다니 다행입니다!
juneheel
reviewed
Aug 11, 2024
Comment on lines
+17
to
+25
| List<String> sortedWords = uniqueWords.stream() | ||
| .sorted((a, b) -> { | ||
| if (a.length() == b.length()) { // 문자열 길이가 같은 경우 | ||
| return a.compareTo(b); // 사전 순으로 | ||
| } else { // 문자열 길이가 다른 경우 | ||
| return Integer.compare(a.length(), b.length()); // 길이 비교 | ||
| } | ||
| }) | ||
| .collect(Collectors.toList()); |
Contributor
There was a problem hiding this comment.
역시 stream과 람다식을 잘 활용해야겠다는 생각이 다시한번드네요.. 일일히 comparator내의 compare을 오버라이딩했는데, stream().sorted() 람다식으로 표현하니 가독성도 늘어나고 처리과정도 확 주는것같습니다👍
Member
Author
There was a problem hiding this comment.
stream을 활용하면 확실히 가독성, 코드 작성에 도움이 많이 되더라구요! 자바에서는 희망같습니다 ㅠ
juneheel
reviewed
Aug 11, 2024
| long[] result = new long[n]; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| String rev = new StringBuilder(strNum[i]).reverse().toString(); |
Contributor
There was a problem hiding this comment.
StringBuilder의 reverse()메서드 사용하신게 인상깊네요😊
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.
문제: BOJ5648. - 역원소 정렬
Arrays.sort(result);정렬은 nlogn의 시간복잡도를 가진다고 알고 있음.Arrays.sort()메서드 사용문제: BOJ1181 - 단어 정렬
정렬의 시간 복잡도는 n log n 으로 알고 있음.
문제: BOJ1822 - 차집합
정렬의 시간 복잡도는 n log n 으로 알고 있음.