Skip to content

Commit 2fd0998

Browse files
committed
edit: fix DaleStudy#229 space complexity
1 parent 8443c85 commit 2fd0998

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

โ€Žsubtree-of-another-tree/EGON.pyโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def isSubtree(self, root: Optional[TreeNode], subRoot: Optional[TreeNode]) -> bo
2222
> O(n) * O(m) ~= O(n * m)
2323
2424
Memory: 17.09 (Beats 9.93%)
25-
Space Complexity: O(max(n, m))
25+
Space Complexity: O(n + m)
2626
- stack์˜ ์ตœ๋Œ€ ํฌ๊ธฐ๋Š” root ํŠธ๋ฆฌ๊ฐ€ ํŽธํ–ฅ๋œ ๊ฒฝ์šฐ์ด๋ฉฐ, ์ด๋Š” root ํŠธ๋ฆฌ์˜ ๋…ธ๋“œ์˜ ์ด ๊ฐฏ์ˆ˜์™€ ๊ฐ™์œผ๋ฏ€๋กœ O(n), upper bound
2727
- is_same_tree ํ•จ์ˆ˜์˜ ์žฌ๊ท€ ์Šคํƒ์˜ ์ตœ๋Œ€ ๊นŠ์ด๋Š” subRoot ํŠธ๋ฆฌ๊ฐ€ ํŽธํ–ฅ๋œ ๊ฒฝ์šฐ์ด๋ฉฐ, ์ด๋Š” subRoot ํŠธ๋ฆฌ์˜ ๋…ธ๋“œ์˜ ์ด ๊ฐฏ์ˆ˜์™€ ๊ฐ™์œผ๋ฏ€๋กœ O(m), upper bound
28-
> O(n) + O(m) ~= O(max(n, m))
28+
> O(n) + O(m) ~= O(n + m)
2929
"""
3030
def solve_dfs(self, root: Optional[TreeNode], subRoot: Optional[TreeNode]) -> bool:
3131

0 commit comments

Comments
ย (0)