Skip to content

Commit d4d22b2

Browse files
authored
Create main.cpp
1 parent 1cd84ca commit d4d22b2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int solve(Node* root, int &i, int k){
4+
if(root == NULL) return -1;
5+
6+
int right = solve(root -> right, i, k);
7+
if(right != -1) return right;
8+
9+
i++;
10+
if(i == k) return root -> data;
11+
12+
return solve(root -> left, i, k);
13+
}
14+
15+
int kthLargest(Node *root, int k) {
16+
int i = 0;
17+
int ans = solve(root, i, k);
18+
19+
return ans;
20+
}
21+
};

0 commit comments

Comments
 (0)