Skip to content

Commit e40f19f

Browse files
committed
docs(105, 106): update React READMEs and Python implementation for binary tree construction problems
1 parent 4f33c84 commit e40f19f

6 files changed

Lines changed: 29 additions & 21 deletions

File tree

Algorithm/BinaryTree/claude sonnet 4.6 extended/105. Construct Binary Tree from Preorder and Inorder Traversal/README_React.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
218218
self,
219219
preorder: list[int],
220220
inorder: list[int],
221-
) -> Optional[TreeNode]:
221+
) -&gt; Optional[TreeNode]:
222222
"""
223223
preorder(前順)と inorder(中順)から二分木を復元する。
224224
Time: O(n) - 各ノードをちょうど1回処理
@@ -248,7 +248,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
248248
# int はイミュータブル(変更不可)なので nonlocal で外側変数を共有する
249249
preorder_idx: int = 0
250250

251-
def build(lo: int, hi: int) -> Optional[TreeNode]:
251+
def build(lo: int, hi: int) -&gt; Optional[TreeNode]:
252252
"""inorder の [lo, hi] 範囲に対応する部分木を再帰構築する"""
253253
nonlocal preorder_idx
254254

Algorithm/BinaryTree/claude sonnet 4.6 extended/106. Construct Binary Tree from Inorder and Postorder Traversal/Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal_Python.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,20 @@ return TreeNode(3) ✅
346346
# リストで包む(ミュータブルオブジェクトに変換する)ことで回避できる
347347

348348
# 方法1: nonlocal を使う(明示的だが宣言が必要)
349-
count = 0
350-
def inner():
351-
nonlocal count # ← これがないと count += 1 で UnboundLocalError になる
352-
count += 1
349+
def outer1():
350+
count = 0
351+
def inner():
352+
nonlocal count # ← これがないと count += 1 で UnboundLocalError になる
353+
count += 1
354+
return inner
353355

354356
# 方法2: リストで包む(nonlocal 不要・慣用句として広く使われる)
355-
count = [0] # int ではなく list[int] にする
356-
def inner():
357-
count[0] += 1 # リストの中身を書き換えるのは「外側変数の再代入」ではない
358-
# → nonlocal 不要
357+
def outer2():
358+
count = [0] # int ではなく list[int] にする
359+
def inner():
360+
count[0] += 1 # リストの中身を書き換えるのは「外側変数の再代入」ではない
361+
# → nonlocal 不要
362+
return inner
359363
```
360364

361365
### dict内包表記 vs `enumerate()` + ループ

Algorithm/BinaryTree/claude sonnet 4.6 extended/106. Construct Binary Tree from Inorder and Postorder Traversal/README_React.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
155155
self,
156156
inorder: List[int],
157157
postorder: List[int]
158-
) -> Optional[TreeNode]:
158+
) -&gt; Optional[TreeNode]:
159159
# Python のデフォルト再帰上限は 1000。
160160
# 完全偏り木では n=3000 段の再帰が必要になるため上限を引き上げる。
161161
sys.setrecursionlimit(10_000)
@@ -169,9 +169,9 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
169169
# リストに包むことで「リストの中身を変える」操作になり nonlocal 不要になる。
170170
post_idx: List[int] = [len(postorder) - 1]
171171

172-
def dfs(left: int, right: int) -> Optional[TreeNode]:
172+
def dfs(left: int, right: int) -&gt; Optional[TreeNode]:
173173
# 終了条件:左端が右端を超えた = この範囲に要素がない = 部分木なし
174-
if left > right:
174+
if left &gt; right:
175175
return None
176176

177177
# postorder の末尾から現在の部分木のルートを取り出す。
@@ -1066,7 +1066,9 @@ <h3 className="mt-0 text-teal-800 text-base font-bold mb-2">{currentStepData.tit
10661066
root.render(React.createElement(StepsApp));
10671067

10681068
// Re-highlight code after React renders
1069-
setTimeout(() => { if (window.Prism) Prism.highlightAll(); }, 300);
1069+
requestAnimationFrame(() => {
1070+
if (window.Prism) Prism.highlightAllUnder(document.getElementById("react-steps"));
1071+
});
10701072
</script>
10711073
</body>
10721074
</html>

public/Algorithm/BinaryTree/claude sonnet 4.6 extended/105. Construct Binary Tree from Preorder and Inorder Traversal/README_React.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
218218
self,
219219
preorder: list[int],
220220
inorder: list[int],
221-
) -> Optional[TreeNode]:
221+
) -&gt; Optional[TreeNode]:
222222
"""
223223
preorder(前順)と inorder(中順)から二分木を復元する。
224224
Time: O(n) - 各ノードをちょうど1回処理
@@ -248,7 +248,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
248248
# int はイミュータブル(変更不可)なので nonlocal で外側変数を共有する
249249
preorder_idx: int = 0
250250

251-
def build(lo: int, hi: int) -> Optional[TreeNode]:
251+
def build(lo: int, hi: int) -&gt; Optional[TreeNode]:
252252
"""inorder の [lo, hi] 範囲に対応する部分木を再帰構築する"""
253253
nonlocal preorder_idx
254254

public/Algorithm/BinaryTree/claude sonnet 4.6 extended/106. Construct Binary Tree from Inorder and Postorder Traversal/README_React.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
155155
self,
156156
inorder: List[int],
157157
postorder: List[int]
158-
) -> Optional[TreeNode]:
158+
) -&gt; Optional[TreeNode]:
159159
# Python のデフォルト再帰上限は 1000。
160160
# 完全偏り木では n=3000 段の再帰が必要になるため上限を引き上げる。
161161
sys.setrecursionlimit(10_000)
@@ -169,9 +169,9 @@ <h2 class="outfit text-[1.9rem] font-bold text-cyan-700 mb-4 pb-2 border-b-[3px]
169169
# リストに包むことで「リストの中身を変える」操作になり nonlocal 不要になる。
170170
post_idx: List[int] = [len(postorder) - 1]
171171

172-
def dfs(left: int, right: int) -> Optional[TreeNode]:
172+
def dfs(left: int, right: int) -&gt; Optional[TreeNode]:
173173
# 終了条件:左端が右端を超えた = この範囲に要素がない = 部分木なし
174-
if left > right:
174+
if left &gt; right:
175175
return None
176176

177177
# postorder の末尾から現在の部分木のルートを取り出す。
@@ -1066,7 +1066,9 @@ <h3 className="mt-0 text-teal-800 text-base font-bold mb-2">{currentStepData.tit
10661066
root.render(React.createElement(StepsApp));
10671067

10681068
// Re-highlight code after React renders
1069-
setTimeout(() => { if (window.Prism) Prism.highlightAll(); }, 300);
1069+
requestAnimationFrame(() => {
1070+
if (window.Prism) Prism.highlightAllUnder(document.getElementById("react-steps"));
1071+
});
10701072
</script>
10711073
</body>
10721074
</html>

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ <h1 class="site-title">
829829

830830
<footer>
831831
<span class="footer-icon">🧪</span>
832-
Generated on 2026-04-26
832+
Generated on 2026-04-27
833833
</footer>
834834

835835
<script>

0 commit comments

Comments
 (0)