# 第三十三周ARTS总结
# Algorithm
4ms | 66.65% Run time
40.1MB | 10.37% Memory
public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> ans = new ArrayList<>();
boolean hasAns = false;
// 只选一个数的答案
for (int i = 0; i < candidates.length; i++) {
if (target > candidates[i]) {
hasAns = true;
} else if (target == candidates[i]) {
List<Integer> temp = new ArrayList<>();
temp.add(target);
ans.add(temp);
}
}
// 如果候选人中所有的数字都比target大
if (!hasAns) {
return ans;
}
for (int i = 0; i < candidates.length; i++) {
int[] rest = Arrays.copyOfRange(candidates, i, candidates.length);
List<List<Integer>> temp = combinationSum(rest, target - candidates[i]);
for (List<Integer> list : temp) {
list.add(0, candidates[i]);
ans.add(list);
}
}
return ans;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Review
# Tip
- 原生
WebView
的内核Android 4.4
之前:WebKit
Android 4.4
之后:chromium
BlinkLayout
:LayoutInflater
的内部类,是FrameLayout
的子类,隔0.5
秒闪烁一次Java
对象在堆中的结构- 头信息(Object Header):用于记录对象状态,在32位系统中占32位,即4字节
- 类指针(Class Pointer):指向当前类父类的指针,在32位系统中占4字节
- 字段(Fields)
注:总大小需8位对齐
- 节约内存原则
- 尽量使用基本类型,而不是包装类型
- 斟酌字段类型,在满足容量前提下,尽量用小字段
- 如果可能,尽量用数组,少用集合
- 小技巧
- 时间用
long/int
表示,不用Date/String
- 短字符串如果能穷举或者转成
ASCII
表示,可以用long/int
表示
- 时间用
Context
三两语Context
有两个直接实现类:ContextImpl
和ContextWrapper
- 所有的实现都由
ContextImpl
实现,ContextWrapper
持有了ContextImpl
Application
、Service
、Activity
都直接或者间接的继承了ContextWrapper
,故他们均持有一个ContextImpl
getApplication
、getApplicationContext
、getBaseContext
的区别getApplication
:获取APP
的Application
实例,作用域为Activity
和Service
getApplicationContext
:获取APP
的Application
实例,作用域为Context
getBaseContext
:获取持有的ContextImpl
实例,作用域为ContextWrapper
# Share
暂无内容