-
-
Notifications
You must be signed in to change notification settings - Fork 193
[Tony] WEEK 12 Solutions #564
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
Changes from 1 commit
5f1ed68
612595a
79fbf03
a14bddf
eda7ce0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||
// TC: O(n) | ||||||||
// retreive all given nodes | ||||||||
// SC: O(1) | ||||||||
// doesn't require additional space | ||||||||
class Solution { | ||||||||
public boolean isSameTree(TreeNode p, TreeNode q) { | ||||||||
if (p == null || q == null) { | ||||||||
if (p == null && q == null) return true; | ||||||||
return false; | ||||||||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😉
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헐 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L7 ~ L10 을 조금 더 줄여서 아래처럼 가능할 것 같습니다! if (p == null || q == null) {
return p == q;
} |
||||||||
} | ||||||||
|
||||||||
if (p.val != q.val) return false; | ||||||||
|
||||||||
return isSameTree(p.left, q.left) && | ||||||||
isSameTree(p.right, q.right); | ||||||||
} | ||||||||
} |
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.
dfs 스택을 사용하는 만큼
O(N)
이지 않을까요~?