Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit cdf0ee3

Browse files
committed
Update problem 572
Runtime can't be O(n) because node values aren't unique
1 parent 4a185e3 commit cdf0ee3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

‎algorithms/572/solution.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ func isSame(s *TreeNode, t *TreeNode) bool {
1515
isSame(s.Left, t.Left) && isSame(s.Right, t.Right)
1616
}
1717

18-
// Time and space complexity: O(n) where n is size of the bigger tree
18+
// Time complexity, O(n*m) where n and m are length of the trees and m <= n
19+
// Space complexity, O(n)
1920
func isSubtree(s *TreeNode, t *TreeNode) bool {
2021
return s != nil &&
2122
(isSame(s, t) || isSubtree(s.Left, t) || isSubtree(s.Right, t))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /