Skip to content

Conversation

GangBean
Copy link
Contributor

@GangBean GangBean commented Dec 15, 2024

답안 제출 문제

체크 리스트

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

@GangBean GangBean added the java label Dec 15, 2024
@GangBean GangBean requested a review from a team as a code owner December 15, 2024 02:21
@GangBean GangBean requested a review from eunhwa99 December 15, 2024 02:22
Copy link
Contributor

@TonyKim9401 TonyKim9401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2주차 문제풀이 고생하셨습니다~!

- space: O(1) -> no extra space is needed
*/
// 0. assign return variable Set
Set<List<Integer>> answer = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복을 피하려고 Set을 사용한게 인상깊네요..!

Comment on lines +31 to +48
if (preorder.length == 0) return null;
if (preorder.length == 1) return new TreeNode(preorder[0]);
int i = 0;
List<Integer> leftPreorder = new ArrayList<>(); // O(N)
List<Integer> leftInorder = new ArrayList<>(); // O(N)
List<Integer> rightPreorder = new ArrayList<>(); // O(N)
List<Integer> rightInorder = new ArrayList<>(); // O(N)
for (; i < inorder.length; i++) { // O(N)
if (inorder[i] == preorder[0]) break;
leftPreorder.add(preorder[i+1]);
leftInorder.add(inorder[i]);
}
for (int idx = i+1; idx < inorder.length; idx++) { // O(N)
rightPreorder.add(preorder[idx]);
rightInorder.add(inorder[idx]);
}

return new TreeNode(preorder[0], buildTree(leftPreorder.stream().mapToInt(Integer::intValue).toArray(), leftInorder.stream().mapToInt(Integer::intValue).toArray()), buildTree(rightPreorder.stream().mapToInt(Integer::intValue).toArray(), rightInorder.stream().mapToInt(Integer::intValue).toArray()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와; 이렇게 푸시는건 상상을 못했네요. dfs로 풀어보시는 것도 좋을것 같습니다!

Comment on lines +18 to +28
Map<Character, Integer> sMap = new HashMap<>();
Map<Character, Integer> tMap = new HashMap<>();

for (char c: s.toCharArray()) {
sMap.put(c, sMap.getOrDefault(c, 0) + 1);
}
for (char c: t.toCharArray()) {
tMap.put(c, tMap.getOrDefault(c, 0) + 1);
}

return Objects.equals(sMap, tMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 s와 t를 .toCharArray()로 바꾼 후 Arrays.sort -> Arrays.equals() 로 비교했는데 Objects.equals로 HashMap 자체를 비교하는 방법도 있군요. 배워갑니다!

@GangBean GangBean merged commit 3854db0 into DaleStudy:main Dec 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants