Skip to content

Conversation

@hyunolike
Copy link

@hyunolike hyunolike commented Nov 14, 2025

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@hyunolike
Copy link
Author

@DaleStudy

@dalestudy
Copy link

dalestudy bot commented Nov 14, 2025

Great job on covering multiple problems with clear, straightforward solutions! Your code is generally clean and easy to follow, which is excellent for maintainability. Here are some constructive suggestions to further improve your submissions:

  1. Time and Space Complexity Comments:
    Including explicit TC and SC comments (e.g., // TC: O(n), SC: O(n)) helps reviewers quickly grasp the efficiency of your solutions. For example, in your containsDuplicate, it's O(n) time and O(n) space due to the HashMap. Adding these comments enhances clarity and demonstrates your understanding.

  2. Algorithm Optimization:

    • For twoSum, the current nested loop results in O(n²). A more efficient approach uses a HashMap to achieve O(n) time:
      Map<Integer, Integer> map = new HashMap<>();
      for (int i = 0; i < nums.length; i++) {
          int complement = target - nums[i];
          if (map.containsKey(complement)) {
              return new int[]{map.get(complement), i};
          }
          map.put(nums[i], i);
      }

    This is a common best practice that improves performance, especially for larger inputs.

  3. Code Readability & Style:

    • Consistent indentation and removing commented-out or debug lines (like your System.out.println) make the code cleaner.
    • For longestConsecutive, using a HashSet instead of sorting can achieve O(n) time, which is more optimal:
      Set<Integer> set = new HashSet<>();
      for (int num : nums) set.add(num);
      int maxLen = 0;
      for (int num : set) {
          if (!set.contains(num - 1)) {
              int currentNum = num;
              int streak = 1;
              while (set.contains(currentNum + 1)) {
                  currentNum++;
                  streak++;
              }
              maxLen = Math.max(maxLen, streak);
          }
      }

    This approach avoids sorting, reducing time complexity.

  4. Edge Case Handling:
    Your code in longestConsecutive correctly handles empty arrays, but explicitly checking for null first (if (nums == null || nums.length == 0)) is a good habit to prevent potential NullPointerException.

  5. Consistency in Variable Naming:
    Using descriptive variable names (e.g., maxLength instead of maxLen) improves readability.

Keep up the good work! Your solutions show solid understanding, and with these minor adjustments, they'll become even more efficient and professional. You're on a great track!

@devyulbae devyulbae self-requested a review November 14, 2025 13:50
@hyunolike
Copy link
Author

@DaleStudy 리뷰해줘

@dalestudy
Copy link

dalestudy bot commented Nov 14, 2025

Great job on submitting multiple solutions in a structured and organized manner! Your code is clear, and the use of comments helps understand your thought process. Here are some constructive suggestions to enhance your solutions further:

  1. Time and Space Complexity Annotations:
    Adding complexity comments (e.g., // TC: O(n), SC: O(n)) at the top of each solution will help you and reviewers quickly grasp efficiency. For example, your containsDuplicate uses a HashMap with O(n) time and O(n) space, which is good, but explicitly noting this improves readability.

  2. Algorithm Optimization:

    • In longestConsecutive, sorting the array results in O(n log n) time. An alternative, more efficient approach uses a HashSet to achieve O(n) time by checking the start of sequences, which is especially beneficial for large datasets.
    • In twoSum, the nested loops lead to O(n^2) complexity. Using a HashMap to store complements can reduce this to O(n).
  3. Code Readability & Practices:

    • For containsDuplicate, instead of HashMap<Integer, Integer>, a HashSet<Integer> suffices since you're only checking existence. This simplifies the code and slightly improves performance.
    • Consistent variable naming helps. For example, in rob, prev1 and prev2 are okay, but maxRob and prevMax might be more descriptive.
  4. Resource Management:

    • In twoSum, returning null if no pair is found is acceptable, but clarifying this behavior in comments or throwing an exception could improve robustness.

Overall, your solutions are on the right track! Incorporating these suggestions will make your code more efficient, readable, and maintainable. Keep up the excellent work—you're demonstrating solid problem-solving skills!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

1 participant