码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-938 Range Sum of BST(二叉搜索树的范围和)

时间:2018-11-13 20:22:37      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:nod   范围   root   tco   tree   style   val   turn   col   

 1 class Solution
 2 {
 3     public:
 4         int rangeSumBST(TreeNode* root, int L, int R)
 5         {
 6             int result = 0;
 7             if(root->left)
 8                 result += rangeSumBST(root->left, L, R);
 9             if(root->right)
10                 result += rangeSumBST(root->right, L, R);
11             
12             if(root->val>=L && root->val<=R)
13                 result += root->val;
14             
15             return result;
16         }
17 };

 

Leetcode-938 Range Sum of BST(二叉搜索树的范围和)

标签:nod   范围   root   tco   tree   style   val   turn   col   

原文地址:https://www.cnblogs.com/Asurudo/p/9953660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!