Skip to content

[shinsj4653] Week 12 Solutions #1605

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

Merged
merged 2 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions non-overlapping-intervals/shinsj4653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
[문제풀이]
# Inputs

# Outputs

# Constraints

# Ideas

[회고]

"""


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
[문제풀이]
# Inputs

# Outputs

# Constraints

# Ideas

[회고]

"""



15 changes: 15 additions & 0 deletions remove-nth-node-from-end-of-list/shinsj4653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
[문제풀이]
# Inputs

# Outputs

# Constraints

# Ideas

[회고]

"""


65 changes: 65 additions & 0 deletions same-tree/shinsj4653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
[문제풀이]
# Inputs
두 이진 트리의 노드 배열들 p, q

# Outputs
두 트리가 같은지 다른지 체크

# Constraints
- The number of nodes in both trees is in the range [0, 100].
- -104 <= Node.val <= 104

# Ideas
둘 다 bfs?? 때리면 될 것 같은데?
동시에 탐색하면서 다른 노드 나오면 바로 종료

[회고]
풀긴 풀었는데 좀 더 깔금한 풀이가 있을까?
->

"""

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import deque


class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
def dfs(p_tree, q_tree):
print('p: ', p_tree)
print('q: ', q_tree)

if p_tree is not None and q_tree is not None and p_tree.val == q_tree.val:
print('add left and right')
return dfs(p_tree.left, q_tree.left) and dfs(p_tree.right, q_tree.right)

if (p_tree == q_tree == None):
return True

if (p_tree is not None and q_tree is None) or \
(p_tree is None and q_tree is not None) or \
(p_tree is not None and q_tree is not None and p_tree.val != q_tree.val):
print("not same!!")
return False

return dfs(p, q)

# 해설
class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
if p is None and q is None:
return True
if p is None or q is None or p.val != q.val:
return False
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)





16 changes: 16 additions & 0 deletions serialize-and-deserialize-binary-tree/shinsj4653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
[문제풀이]
# Inputs

# Outputs

# Constraints

# Ideas

[회고]

"""