Skip to content

Commit 4534a73

Browse files
Merge pull request #105 from hiveryeah/master
第三周作业#23
2 parents e65ec9c + f4985d3 commit 4534a73

File tree

7 files changed

+131
-3
lines changed

7 files changed

+131
-3
lines changed

Week_01/id_23/NOTE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#### 关于Big O
66
数据结构和算法本身解决的是“快”和“省”的问题。大O表示的是算法运行时间的增速!
77

8-
极客时间版权所有: https://time.geekbang.org/column/article/40036
98
#### 关于递归 Recursion
109
“如果使用循环,程序地性能可能更高;如果适用递归,程序可能更容易理解。如何选择要看什么对你来说更重要” --Leigh Caldwell
1110
递归套路模板 1. Recursion terminator2. Process logic 3.Drill down 4.Reverse the current level status if needed

Week_02/id_23/LeetCode_03_23.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
2+
//
3+
// 示例 1:
4+
//
5+
// 输入: "abcabcbb"
6+
//输出: 3
7+
//解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
8+
//
9+
//
10+
// 示例 2:
11+
//
12+
// 输入: "bbbbb"
13+
//输出: 1
14+
//解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
15+
//
16+
//
17+
// 示例 3:
18+
//
19+
// 输入: "pwwkew"
20+
//输出: 3
21+
//解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。
22+
//请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。
23+
//
24+
//
25+
public class Solution {
26+
public int lengthOfLongestSubstring(String s) {
27+
int n = s.length(), ans = 0;
28+
// current index of character
29+
int[] index = new int[128];
30+
for (int j = 0, i = 0; j < n; j++) {
31+
i = Math.max(index[s.charAt(j)], i);
32+
ans = Math.max(ans, j - i + 1);
33+
index[s.charAt(j)] = j + 1;
34+
}
35+
return ans;
36+
}
37+
}

Week_02/id_23/LeetCode_111_23.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public int minDepth(TreeNode root) {
12+
if (root == null) {
13+
return 0;
14+
}
15+
if (root.left == null) {
16+
return minDepth(root.right) + 1;
17+
}
18+
if (root.right == null) {
19+
return minDepth(root.left) + 1;
20+
}
21+
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
22+
}
23+
}

Week_02/id_23/NOTE.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# 学习笔记
1+
# 学习笔记
2+
整数数组作为直接访问表来替换 Map,是大神一样的操作哇。
3+
int [26] 用于字母 ‘a’ - ‘z’ 或 ‘A’ - ‘Z’
4+
int [128] 用于ASCII码
5+
int [256] 用于扩展ASCII码
6+
以后关于char的题目可以都用这种思路去降维思考。

Week_03/id_23/LeetCode_104.1_23

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//给定一个二叉树,找出其最大深度。
2+
//
3+
// 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
4+
//
5+
// 说明: 叶子节点是指没有子节点的节点。
6+
//
7+
// 示例:
8+
//给定二叉树 [3,9,20,null,null,15,7],
9+
//
10+
// 3
11+
// / \
12+
// 9 20
13+
// / \
14+
// 15 7
15+
//
16+
// 返回它的最大深度 3 。
17+
//
18+
19+
/**
20+
* Definition for a binary tree node.
21+
* public class TreeNode {
22+
* int val;
23+
* TreeNode left;
24+
* TreeNode right;
25+
* TreeNode(int x) { val = x; }
26+
* }
27+
*/
28+
class Solution {
29+
public int maxDepth(TreeNode root) {
30+
if (root == null) {
31+
return 0;
32+
} else {
33+
int left_height = maxDepth(root.left);
34+
int right_height = maxDepth(root.right);
35+
return java.lang.Math.max(left_height, right_height) + 1;
36+
}
37+
}
38+
}

Week_03/id_23/LeetCode_104.2_23

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public int maxDepth(TreeNode root) {
12+
return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
13+
}
14+
}

Week_03/id_23/NOTE.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
# 学习笔记
1+
# 学习笔记
2+
###本周总结
3+
#### 关于图的定义
4+
图的表示: 邻接表 和 邻接矩阵
5+
图可以分为 有向图 和无向图
6+
无向图是一种特殊的有向图
7+
有权图 和 无权图
8+
9+
#### 关于图相关的算法与问题
10+
图的遍历: DFS BFS 常见可以解决的问题有: 联通分量 Flood Fill 寻路 走迷宫 迷宫生成 无权图的最短路径 环的判断
11+
最小生成树问题(Minimum Spanning Tree) Prim Kruskal
12+
最短路径问题(Shortest Path) Dijkstra Bellman-Ford
13+
拓扑排序(Topological sorting)

0 commit comments

Comments
 (0)