# 第三十三周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

# Review

# Tip

  • 原生WebView的内核
    • Android 4.4之前:WebKit
    • Android 4.4之后:chromium
  • BlinkLayoutLayoutInflater的内部类,是FrameLayout的子类,隔0.5秒闪烁一次
  • Java对象在堆中的结构
    • 头信息(Object Header):用于记录对象状态,在32位系统中占32位,即4字节
    • 类指针(Class Pointer):指向当前类父类的指针,在32位系统中占4字节
    • 字段(Fields)
      注:总大小需8位对齐
  • 节约内存原则
    • 尽量使用基本类型,而不是包装类型
    • 斟酌字段类型,在满足容量前提下,尽量用小字段
    • 如果可能,尽量用数组,少用集合
    • 小技巧
      • 时间用long/int表示,不用Date/String
      • 短字符串如果能穷举或者转成ASCII表示,可以用long/int表示
  • Context三两语
    • Context有两个直接实现类:ContextImplContextWrapper
    • 所有的实现都由ContextImpl实现,ContextWrapper持有了ContextImpl
    • ApplicationServiceActivity都直接或者间接的继承了ContextWrapper,故他们均持有一个ContextImpl
    • getApplicationgetApplicationContextgetBaseContext的区别
      • getApplication:获取APPApplication实例,作用域为ActivityService
      • getApplicationContext:获取APPApplication实例,作用域为Context
      • getBaseContext:获取持有的ContextImpl实例,作用域为ContextWrapper

# Share

暂无内容

更新时间: 10/20/2022, 7:04:01 AM