File tree Expand file tree Collapse file tree 3 files changed +50
-11
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 3 files changed +50
-11
lines changed Original file line number Diff line number Diff line change 29
29
</dependency >
30
30
</dependencies >
31
31
32
+ <reporting >
33
+ <plugins >
34
+ <plugin >
35
+ <groupId >org.apache.maven.plugins</groupId >
36
+ <artifactId >maven-checkstyle-plugin</artifactId >
37
+ <version >2.17</version >
38
+ <reportSets >
39
+ <reportSet >
40
+ <reports >
41
+ <report >checkstyle</report >
42
+ </reports >
43
+ </reportSet >
44
+ </reportSets >
45
+ </plugin >
46
+ </plugins >
47
+ </reporting >
48
+
32
49
</project >
Original file line number Diff line number Diff line change 3
3
import com .fishercoder .common .classes .TreeNode ;
4
4
5
5
/**104. Maximum Depth of Binary Tree
6
- *
7
6
Given a binary tree, find its maximum depth.
8
-
9
- The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.*/
7
+ The maximum depth is the number of
8
+ nodes along the longest path from the root node down to the farthest leaf node.
9
+ */
10
10
public class _104 {
11
11
12
12
//more verbose version
13
13
public int maxDepth (TreeNode root ) {
14
14
if (root == null ) return 0 ;
15
- int leftDepth = 0 ;
16
- if (root .left != null ) leftDepth = maxDepth (root .left )+1 ;
17
- int rightDepth = 0 ;
18
- if (root .right != null ) rightDepth = maxDepth (root .right )+1 ;
19
- return Math .max (1 , Math .max (leftDepth , rightDepth ));//the reason we need to max with 1 here is actually
20
- //for this case: if(root != null), it's implicit here, because we checked root.left != null and root.right != null
21
- //then it comes to root != null
22
- //example test case for the above scenario: nums = {1,1,1}
15
+ int leftDepth = maxDepth (root .left )+1 ;
16
+ int rightDepth = maxDepth (root .right )+1 ;
17
+ return Math .max (1 , Math .max (leftDepth , rightDepth ));
23
18
}
24
19
25
20
//more concise version
Original file line number Diff line number Diff line change
1
+ package com .fishercoder .solutions ;
2
+
3
+ /**
4
+ * 564. Find the Closest Palindrome
5
+ *
6
+ * Given an integer n, find the closest integer (not including itself), which is a palindrome.
7
+
8
+ The 'closest' is defined as absolute difference minimized between two integers.
9
+
10
+ Example 1:
11
+
12
+ Input: "123"
13
+ Output: "121"
14
+
15
+ Note:
16
+
17
+ The input n is a positive integer represented by string, whose length will not exceed 18.
18
+ If there is a tie, return the smaller one as answer.
19
+
20
+ */
21
+ public class _564 {
22
+
23
+ public String nearestPalindromic (String n ) {
24
+ return "" ;
25
+ }
26
+
27
+ }
You can’t perform that action at this time.
0 commit comments