You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ebook/tree/Tree.tex
+184-1Lines changed: 184 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -281,4 +281,187 @@ \subsubsection{Solution}
281
281
}
282
282
\end{Code}
283
283
284
-
\newpage
284
+
\newpage
285
+
286
+
\section{Binary Tree Maximum Path Sum} %%%%%%%%%%%%%%%%%%%%%%
287
+
288
+
\subsubsection{Description}
289
+
290
+
Given a binary tree, find the maximum path sum.
291
+
292
+
For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.
293
+
294
+
For example:
295
+
296
+
Given the below binary tree,
297
+
\begin{Code}
298
+
1
299
+
/ \
300
+
2 3
301
+
\end{Code}
302
+
303
+
Return 6.
304
+
305
+
\subsubsection{Solution}
306
+
307
+
\begin{Code}
308
+
public int maxPathSum(TreeNode root) {
309
+
return maxPathSum(root, null);
310
+
}
311
+
312
+
/**
313
+
* max表示包含root的单边路径最大和
314
+
*/
315
+
private int maxPathSum(TreeNode root, int[] max) {
0 commit comments