File tree Expand file tree Collapse file tree 2 files changed +4
-19
lines changed Expand file tree Collapse file tree 2 files changed +4
-19
lines changed Original file line number Diff line number Diff line change 9
9
| #Number | Name | Difficulty | Solution | Youtube |
10
10
| :--------:| ------| :----------:| :--------:| :----------------------:|
11
11
| 1 | [ Two Sum] ( https://leetcode.com/problems/two-sum/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/TwoSum.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/two_sum.py ) |
12
- | 7 | [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer / ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ReverseInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/reverse_integer.py ) |
12
+ | 7 | [ Reverse Integer] ( https://leetcode.com/problems/reverse-isnteger / ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ReverseInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/reverse_integer.py ) |
13
13
| 9 | [ PalindromeNumber] ( https://leetcode.com/problems/palindrome-number/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/PalindromeNumber.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/palindrome_number.py ) |
14
14
| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RomanToInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/roman_to_integer.py ) |
15
15
| 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/longest_common_prefix.py ) |
Original file line number Diff line number Diff line change @@ -10,24 +10,9 @@ public boolean isSymmetric(TreeNode root) {
10
10
}
11
11
12
12
public boolean isSymmetric (TreeNode p , TreeNode q ) {
13
- if (p == null && q = = null ) {
14
- return true ;
13
+ if (p != null && q ! = null ) {
14
+ return p . val == q . val && isSymmetric ( p . left , q . right ) && isSymmetric ( p . right , q . left ) ;
15
15
}
16
-
17
- if (p == null || q == null || p .val != q .val ) {
18
- return false ;
19
- }
20
-
21
- boolean left = (p .left == null && q .right == null ) || (p .left != null && q .right != null );
22
- if (p .left != null && q .right != null ) {
23
- left = isSymmetric (p .left , q .right );
24
- }
25
-
26
- boolean right = (p .right == null && q .left == null ) || (p .right != null && q .left != null );
27
- if (p .right != null && q .left != null ) {
28
- right = isSymmetric (p .right , q .left );
29
- }
30
-
31
- return left && right ;
16
+ return p == q ;
32
17
}
33
18
}
You can’t perform that action at this time.
0 commit comments