GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode-me/BinaryTreeMaximumPathSum.cpp at master · yvxiang/leetcode-me Expand file tree/ Copy pathBinaryTreeMaximumPathSum.cppMore file actions 19 lines (19 loc) · 680 Bytes / Copy pathBinaryTreeMaximumPathSum.cppFile metadata and controls19 lines (19 loc) · 680 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution { public: int maxPathSum(TreeNode* root) { int cur_max_sum = INT_MIN; check_max_sum(root, cur_max_sum); return cur_max_sum; } private: int check_max_sum(TreeNode* root, int& cur_max_sum) { if (!root) { return 0; } int left_max = check_max_sum(root->left, cur_max_sum); int right_max = check_max_sum(root->right, cur_max_sum); cur_max_sum = max(cur_max_sum, max(root->val, max(root->val + left_max + right_max, max(root->val + left_max, root->val + right_max)))); return max(root->val, max(root->val + left_max, root->val + right_max)); } }; |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |