일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- zeros
- Plotting
- Deep learning
- EOI
- 컴퓨터과학과
- 조지아텍
- 기본
- MATLAB
- 선형대수
- 마니토바
- 개발자
- 방송통신대학교
- 딥러닝
- C++
- 프로그래머스
- cpp
- 매트랩
- mpnp
- LV1
- 방통대
- 주정부이민
- 온라인석사
- leetcode
- 코딩테스트
- omscs
- 캐나다 영주권
- machine learning
- 알고리즘
- 머신러닝
- LAA
Archives
- Today
- Total
Krononberg
leetcode) 938. Range Sum of BST c++ 본문
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int sum =0;
int rangeSumBST(TreeNode* root, int low, int high) {
if(root!=nullptr){
if(root->val >=low && root->val <=high) sum += root->val;
rangeSumBST(root->left,low,high);
rangeSumBST(root->right,low,high);
}
return sum;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1656. Design an Ordered Stream.cpp (0) | 2021.09.26 |
---|---|
leetcode) 1637. Widest Vertical Area Between Two Points Containing No Points c++ (0) | 2021.09.23 |
Leetcode) 1315. Sum of Nodes with Even-Valued Grandparent c++ (0) | 2021.09.21 |
leetcode) 1282. Group the People Given the Group Size They Belong To c++ (0) | 2021.09.21 |
leetcode) 807. Max Increase to Keep City Skyline c++ (0) | 2021.09.20 |