File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class TreeNode {
2+ TreeNode left ;
3+ TreeNode right ;
4+ int value ;
5+
6+ }
7+ class Solution {
8+ public int maxDepth (TreeNode root ) {
9+ if (root == null ) {
10+ return 0 ;
11+ } else {
12+ int left_height = maxDepth (root .left );
13+ int right_height = maxDepth (root .right );
14+ return java .lang .Math .max (left_height , right_height ) + 1 ;
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ import java .util .PriorityQueue ;
2+
3+ class LeetCode_703_091 {
4+ final PriorityQueue <Integer > q ;
5+ final int k ;
6+ public LeetCode_703_091 (int k , int [] nums ) {
7+ this .k = k ;
8+ q = new PriorityQueue <Integer >(k );
9+ for (int i : nums ) {
10+ add (i );
11+ }
12+ }
13+
14+ public int add (int val ) {
15+ if (q .size () < k ) {
16+ q .offer (val );
17+
18+ }
19+ else if (q .peek () < val ) {
20+ q .poll ();
21+ q .offer (val );
22+ }
23+ return q .peek ();
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments