Skip to content

Commit e7c6761

Browse files
authored
Merge pull request gzc426#314 from za1275952454/master
1
2 parents 467c606 + 3fdaf13 commit e7c6761

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

2018.12.04-leetcode101/fish.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
```
2+
class Solution {
3+
public boolean isSymmetric(TreeNode treeNode) {
4+
if (treeNode == null) {
5+
return true;
6+
}else {
7+
return isSymmetric(treeNode.getLeft(), treeNode.getRight());
8+
}
9+
}
10+
11+
public boolean isSymmetric(TreeNode left, TreeNode right) {
12+
if (left == null && right == null) {
13+
return true;
14+
}
15+
if (left == null || right == null) {
16+
return false;
17+
}
18+
if (left.getVal() != right.getVal()) {
19+
return false;
20+
}
21+
return isSymmetric(left.getLeft(), right.getRight()) && isSymmetric(left.getRight(), right.getLeft());
22+
}
23+
}
24+
class TreeNode{
25+
private int val;
26+
private TreeNode left;
27+
private TreeNode right;
28+
29+
public TreeNode(int val, TreeNode left, TreeNode right) {
30+
this.val = val;
31+
this.left = left;
32+
this.right = right;
33+
}
34+
35+
public int getVal() {
36+
return val;
37+
}
38+
39+
public void setVal(int val) {
40+
this.val = val;
41+
}
42+
43+
public TreeNode getLeft() {
44+
return left;
45+
}
46+
47+
public void setLeft(TreeNode left) {
48+
this.left = left;
49+
}
50+
51+
public TreeNode getRight() {
52+
return right;
53+
}
54+
55+
public void setRight(TreeNode right) {
56+
this.right = right;
57+
}
58+
}

2018.12.3-leetcode58/fish.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
>给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
2+
>如果不存在最后一个单词,请返回 0 。
3+
>说明:一个单词是指由字母组成,但不包含任何空格的字符串。
4+
5+
```
6+
public static int lengthOfLastWord(String str){
7+
String trim = str.trim();
8+
if (str.matches("[a-zA-Z ]*") && !trim.isEmpty()) {
9+
int index = trim.lastIndexOf(' ');
10+
return index < 0 ? trim.length() : trim.length() - index - 1;
11+
}
12+
return 0;
13+
}

0 commit comments

Comments
 (0)