File tree 3 files changed +66
-3
lines changed
Algorithm/src/leetCode/subject/number51_100
3 files changed +66
-3
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ public class Departmen{}
228
228
229
229
230
230
231
- ### 泛化generalization
231
+ ### 泛化generalization(继承)
232
232
233
233
1 . 泛化关系实际上就是` 继承 ` 关系,他是依赖关系的特例
234
234
@@ -650,6 +650,7 @@ class Singleton {
650
650
class Singleton6 {
651
651
// 注意这里volatile========================
652
652
private static volatile Singleton6 instance;
653
+ // 构造器需要私有化
653
654
private Singleton6 () {}
654
655
655
656
// ========提供一个静态的公有方法,加入双重检查代码,解决线程安全问题, 同时解决懒加载问题==========
@@ -1928,9 +1929,9 @@ public class Department extends OrganizationComponent {
1928
1929
1929
1930
3. 代理模式有不同的形式, 主要有三种:
1930
1931
1931
- 1. 静态代理
1932
+ 1. 静态代理(接口 / 继承)
1932
1933
2. 动态代理 (JDK / 接口代理)
1933
- 3. Cglib 代理 (可以在内存 动态的创建对象,而不需要实现接口, 他是属于动态代理的范畴) 。
1934
+ 3. Cglib 代理 (内存中构建目标对象子类。 可以在内存 动态的创建对象,而不需要实现接口, 他是属于动态代理的范畴) 。
1934
1935
1935
1936
4. 代理模式示意图
1936
1937
@@ -1996,6 +1997,7 @@ public class Department extends OrganizationComponent {
1996
1997
2. JDK 实现代理只需要使用 `newProxyInstance` 方法,但是该方法需要接收三个参数,完整的写法是:
1997
1998
1998
1999
```java
2000
+ // 方法
1999
2001
static Object newProxyInstance
2000
2002
(ClassLoader loader, Class [] interfaces,InvocationHandler h)
2001
2003
You can’t perform that action at this time.
0 commit comments