# 第六十七周ARTS总结

# Algorithm

0ms | 100.00% Run time
39.1MB | 54.08% Memory

public void merge(int[] nums1, int m, int[] nums2, int n) {
    if (nums2.length == 0) {
        return;
    }

    int[] temp = new int[nums1.length];

    int i = 0;// nums1当前索引
    int j = 0;// nums2当前索引
    int k = 0;// temp当前索引

    while (i < m || j < n) {
        if (i >= m) {
            temp[k] = nums2[j];
            j++;
            k++;
        } else if (j >= n) {
            temp[k] = nums1[i];
            i++;
            k++;
        } else if (nums1[i] < nums2[j]) {
            temp[k] = nums1[i];
            i++;
            k++;
        } else if (nums1[i] > nums2[j]) {
            temp[k] = nums2[j];
            j++;
            k++;
        } else {
            temp[k] = nums1[i];

            i++;
            k++;

            temp[k] = nums2[j];

            j++;
            k++;
        }
    }

    for (int t = 0; t < temp.length; t++) {
        nums1[t] = temp[t];
    }
}
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
34
35
36
37
38
39
40
41
42
43
44
45

# Review

# Tip

  • 最好的判断图片格式的方法:
    String filePath = file.getPath();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, options);
    
    String mimeType = options.outMimeType;
    LogUtils.d(TAG, "图片类型1:" + mimeType);
    
    1
    2
    3
    4
    5
    6
    7
  • 可利用layout_constraintWidth_maxlayout_constraintWidth_percent对控件做最大宽度限制(百分比)
  • TextView设置上下左右图标的时候最好用setCompoundDrawablesWithIntrinsicBounds而不是setCompoundDrawables,因为需要先设置DrawablesetBounds
  • Dalvik虚拟机(Android 5.0 [API 21]之前)同时只能加载一个dex文件,因此某些SDK要求代码放在主dex中;ART虚拟机(Android 5.0 [API 21]之后)可同时加载多个dex文件,因此不必这么做
  • 反射的基本用法:
    val clazz = picker::class.java
    val filed = clazz.getDeclaredField("mPaint")
    filed.isAccessible = true
    val xxx = filed.get(picker) as Paint
    xxx.isFakeBoldText = true
    
    1
    2
    3
    4
    5

# Share

暂无内容

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