Skip to content

Commit 72d0449

Browse files
committed
docs: refine recursion limit warnings and deque explanation in Path_Sum_Python.md
1 parent 81ff937 commit 72d0449

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

Algorithm/BinaryTree/leetcode/112. Path Sum/claude sonnet 4.6 adaptive/Path_Sum_Python.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Pythonの再帰(関数が自分自身を呼び出すこと)にはデフォ
2323
### 競技プログラミング視点
2424

2525
- 制約分析:ノード数 `[0, 5000]`。全ノードを一度ずつ訪れる O(n) で十分間に合う
26-
- 最速手法:再帰DFS(深さ優先探索)。Pythonの再帰はオーバーヘッドがあるが、ノード数5000以下なら実用上問題なし
26+
- 最速手法:再帰DFS。ただしCPythonのデフォルト再帰制限(約1000)では、5000ノードの偏った木で RecursionError が発生する。競技環境や平均的なケースでは最速だが、最悪ケースの深さを考慮するなら sys.setrecursionlimit() を調整するか、反復DFS(スタック使用)が安全。
2727
- メモリ最小化:追加のデータ構造を使わず、関数呼び出しスタックのみ利用。空間計算量 O(h)(hは木の高さ)
2828

2929
### 業務開発視点
@@ -149,9 +149,9 @@ class Solution:
149149
return False
150150

151151
# --- 反復DFS の準備 ---
152-
# deque をスタック(後から積んだものを先に取り出す)として使う
152+
# 再帰を避け、Python の再帰深度制限(約1000)を回避するために明示的なスタックを使用
153153
# (ノード, 現時点までの残り目標値) のペアを積んでいく。
154-
# list でも動くが、deque の pop() は内部が C 実装のため若干高速
154+
# スタックとしての意図を明確にし、必要に応じて効率的な popleft() も可能な deque を採用
155155
stack: deque[tuple[TreeNode, int]] = deque()
156156

157157
# 最初は根ノードと初期の targetSum をスタックに積む。

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ <h1 class="site-title">
509509
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/BinarySearch/leetcode/81.%20Search%20in%20Rotated%20Sorted%20Array%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Search in Rotated Sorted Array II - Technical Analysis</span></span><span class="file-path">Algorithm/BinarySearch/leetcode/81. Search in Rotated Sorted Array II/Claude/README.html</span></a></li>
510510
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/73.%20Set%20Matrix%20Zeroes/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Set Matrix Zeroes Algorithm - Python Implementation</span></span><span class="file-path">Algorithm/Other/leetcode/73. Set Matrix Zeroes/Claude/README.html</span></a></li>
511511
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Dutch%20National%20Flag/leetcode/75.%20Sort%20Colors/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Sort Colors Algorithm - Interactive Technical Guide</span></span><span class="file-path">Algorithm/Dutch National Flag/leetcode/75. Sort Colors/Claude/README.html</span></a></li>
512-
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/54.%20Spiral%20Matrix/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/54. Spiral Matrix/Claude/README.html</span></a></li>
513512
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/59.%20Spiral%20Matrix%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/59. Spiral Matrix II/Claude/README.html</span></a></li>
513+
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/54.%20Spiral%20Matrix/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/54. Spiral Matrix/Claude/README.html</span></a></li>
514514
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/90.%20Subsets%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Subsets II - 反復的拡張法による重複排除 | アルゴリズム解説</span></span><span class="file-path">Algorithm/Other/leetcode/90. Subsets II/Claude/README.html</span></a></li>
515515
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/TwoPointers/leetcode/80.%20Remove%20Duplicates%20from%20Sorted%20Array%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Two-Pointer Algorithm: Remove Duplicates from Sorted Array II</span></span><span class="file-path">Algorithm/TwoPointers/leetcode/80. Remove Duplicates from Sorted Array II/Claude/README.html</span></a></li>
516516
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/BinarySearch/leetcode/34.%20Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/READEME-typescript.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">TypeScript Binary Search Performance Analysis</span></span><span class="file-path">Algorithm/BinarySearch/leetcode/34. Find First and Last Position of Element in Sorted Array/READEME-typescript.html</span></a></li>
@@ -693,8 +693,8 @@ <h1 class="site-title">
693693
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/BinarySearch/leetcode/81.%20Search%20in%20Rotated%20Sorted%20Array%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Search in Rotated Sorted Array II - Technical Analysis</span></span><span class="file-path">Algorithm/BinarySearch/leetcode/81. Search in Rotated Sorted Array II/Claude/README.html</span></a></li>
694694
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/73.%20Set%20Matrix%20Zeroes/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Set Matrix Zeroes Algorithm - Python Implementation</span></span><span class="file-path">Algorithm/Other/leetcode/73. Set Matrix Zeroes/Claude/README.html</span></a></li>
695695
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Dutch%20National%20Flag/leetcode/75.%20Sort%20Colors/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Sort Colors Algorithm - Interactive Technical Guide</span></span><span class="file-path">Algorithm/Dutch National Flag/leetcode/75. Sort Colors/Claude/README.html</span></a></li>
696-
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/54.%20Spiral%20Matrix/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/54. Spiral Matrix/Claude/README.html</span></a></li>
697696
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/59.%20Spiral%20Matrix%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/59. Spiral Matrix II/Claude/README.html</span></a></li>
697+
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/54.%20Spiral%20Matrix/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Spiral Matrix Algorithm Analysis</span></span><span class="file-path">Algorithm/Other/leetcode/54. Spiral Matrix/Claude/README.html</span></a></li>
698698
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/Other/leetcode/90.%20Subsets%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Subsets II - 反復的拡張法による重複排除 | アルゴリズム解説</span></span><span class="file-path">Algorithm/Other/leetcode/90. Subsets II/Claude/README.html</span></a></li>
699699
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/TwoPointers/leetcode/80.%20Remove%20Duplicates%20from%20Sorted%20Array%20II/Claude/README.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">Two-Pointer Algorithm: Remove Duplicates from Sorted Array II</span></span><span class="file-path">Algorithm/TwoPointers/leetcode/80. Remove Duplicates from Sorted Array II/Claude/README.html</span></a></li>
700700
<li class="file-item" data-category="algorithm"><a class="file-link" href="Algorithm/BinarySearch/leetcode/34.%20Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/READEME-typescript.html"><span class="card-header"><span class="card-icon">🧩</span><span class="card-title">TypeScript Binary Search Performance Analysis</span></span><span class="file-path">Algorithm/BinarySearch/leetcode/34. Find First and Last Position of Element in Sorted Array/READEME-typescript.html</span></a></li>

0 commit comments

Comments
 (0)