Skip to content

Commit f4bd1aa

Browse files
committed
add leetcode: 62,64
1 parent 2e1f8c4 commit f4bd1aa

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package leetCode.subject.number51_100;
2+
3+
/**
4+
* @author : CodeWater
5+
* @create :2022-08-04-22:13
6+
* @Function Description :62. 不同路径
7+
*/
8+
public class _62DifferentPath {
9+
class Solution {
10+
/**f(i , j )从起点走到[i,j]的方案。
11+
去除第0行和第0列的边界情况,每一步都是有上方和左边走过来的。所以当前方案,由上边和
12+
左边相加即可
13+
*/
14+
public int uniquePaths(int m, int n) {
15+
int[][] f = new int[n][m];
16+
for( int i = 0 ; i < n ; i++ ){
17+
for( int j = 0 ; j < m ; j++ ){
18+
// 在起点方案数为1
19+
if( i == 0 && j == 0 ) f[i][j] = 1;
20+
else{
21+
// 不在第0列,由左边列的值加来
22+
if( i != 0 ) f[i][j] += f[i - 1][j];
23+
// 不在第0行,由上一行的值加过来
24+
if( j != 0 ) f[i][j] += f[i][j - 1];
25+
}
26+
}
27+
}
28+
29+
return f[n - 1][m - 1];
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package leetCode.subject.number51_100;
2+
3+
/**
4+
* @author : CodeWater
5+
* @create :2022-08-04-22:35
6+
* @Function Description :64. 最小路径和
7+
*/
8+
public class _64TheMinimumPathAnd {
9+
class Solution {
10+
public int minPathSum(int[][] grid) {
11+
int n = grid.length;
12+
if( n == 0 ) return 0;
13+
int m = grid[0].length;
14+
15+
int[][] f = new int[n][m];
16+
for( int i = 0 ; i < n ; i++ ){
17+
for( int j = 0 ; j < m ; j++ ){
18+
if( i == 0 && j == 0 ) f[i][j] = grid[i][j];
19+
else if( i == 0 ) f[i][j] = f[i][j - 1] + grid[i][j];
20+
else if( j == 0 ) f[i][j] = f[i - 1][j] + grid[i][j];
21+
// 不在边界处:有上和左边的两种情况走到当前位置,看那个值更小,然后加上当前值
22+
else f[i][j] = Math.min( f[i][j - 1] , f[i - 1][j] ) + grid[i][j];
23+
}
24+
}
25+
26+
return f[n - 1][m - 1];
27+
}
28+
}
29+
}

notes/desgin pattern/设计模式.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public class Departmen{}
228228

229229

230230

231-
### 泛化generalization
231+
### 泛化generalization(继承)
232232

233233
1. 泛化关系实际上就是`继承`关系,他是依赖关系的特例
234234

@@ -650,6 +650,7 @@ class Singleton {
650650
class Singleton6 {
651651
// 注意这里volatile========================
652652
private static volatile Singleton6 instance;
653+
//构造器需要私有化
653654
private Singleton6() {}
654655

655656
//========提供一个静态的公有方法,加入双重检查代码,解决线程安全问题, 同时解决懒加载问题==========
@@ -1928,9 +1929,9 @@ public class Department extends OrganizationComponent {
19281929

19291930
3. 代理模式有不同的形式, 主要有三种:
19301931

1931-
1. 静态代理
1932+
1. 静态代理(接口/继承)
19321933
2. 动态代理 (JDK /接口代理)
1933-
3. Cglib 代理 (可以在内存 动态的创建对象,而不需要实现接口, 他是属于动态代理的范畴) 。
1934+
3. Cglib 代理 (内存中构建目标对象子类。可以在内存 动态的创建对象,而不需要实现接口, 他是属于动态代理的范畴) 。
19341935

19351936
4. 代理模式示意图
19361937

@@ -1996,6 +1997,7 @@ public class Department extends OrganizationComponent {
19961997
2. JDK 实现代理只需要使用 `newProxyInstance` 方法,但是该方法需要接收三个参数,完整的写法是:
19971998

19981999
```java
2000+
//方法
19992001
static Object newProxyInstance
20002002
(ClassLoader loader, Class[] interfaces,InvocationHandler h)
20012003

0 commit comments

Comments
 (0)