Technology Sharing

Leetcode--Maximum path sum in a binary tree

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Leetcode address:Maximum path sum in a binary tree
A path in a binary tree is defined as a sequence of nodes with an edge between each pair of adjacent nodes. The same node appears at most once in a path sequence. The path contains at least one node and does not necessarily pass through the root node.

The path sum is the sum of the values ​​of each node in the path.

Given a binary tree root node root, return its maximum path sum.

Example 1:
![Insert image description here](https://i-blog.csdnimg.cn/direct/bbb8777d4de24c8e9c32da9cb9e1f00f.png

Input: root = [1,2,3]
Output: 6
Explanation: The optimal path is 2 -