# 第三十三周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之前:WebKitAndroid 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,故他们均持有一个ContextImplgetApplication、getApplicationContext、getBaseContext的区别getApplication:获取APP的Application实例,作用域为Activity和ServicegetApplicationContext:获取APP的Application实例,作用域为ContextgetBaseContext:获取持有的ContextImpl实例,作用域为ContextWrapper
# Share
暂无内容