Skip to content

Commit 6cf867d

Browse files
committed
Time: 15 ms (54.84%), Space: 22 MB (6.84%) - LeetHub
1 parent 0a0f562 commit 6cf867d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: 0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
1010
* };
1111
*/
12-
1312
class Solution {
1413
public:
15-
void helper(TreeNode* root, vector<int> & ans) {
16-
if(root==NULL)
14+
void inOrder(TreeNode* root, vector<int>& ans) {
15+
if(root == NULL) {
1716
return;
17+
}
1818

19-
helper(root->left, ans);
19+
inOrder(root->left, ans);
2020
ans.push_back (root->val);
21-
helper(root->right, ans);
21+
inOrder(root->right, ans);
2222
}
2323

2424
bool isValidBST(TreeNode* root) {
2525
vector<int> ans;
26-
helper(root, ans);
26+
inOrder(root, ans);
2727

2828
for(int i=0; i<ans.size()-1; i++) {
29-
if(ans[i] >= ans[i+1])
29+
if(ans[i] >= ans[i+1]) {
3030
return false;
31+
}
3132
}
3233

3334
return true;
3435
}
35-
3636
};

0 commit comments

Comments
 (0)