# 第三十七周ARTS总结

# Algorithm

12ms | 20.40% Run time
37MB | 100.00% Memory

public String multiply(String num1, String num2) {
    // 判断是否有0
    if ("0".equals(num1) || "0".equals(num2)) {
        return "0";
    }

    // 构造一个数组用来存放最终结果
    int[] ans = new int[num1.length() + num2.length()];

    for (int i = 0; i < num1.length(); i++) {
        for (int j = 0; j < num2.length(); j++) {
            int num = (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
            insert(ans, num,
                    (num1.length() - 1 - i) + (num2.length() - 1 - j));
        }
    }

    // 输出
    StringBuilder sb = new StringBuilder();
    boolean start = false;
    for (int i = ans.length - 1; i >= 0; i--) {
        if (ans[i] == 0 && !start) {
            continue;
        } else {
            start = true;
            sb.append(Integer.toString(ans[i]));
        }
    }

    return sb.toString();
}

/**
 * 将数字插入数组
 *
 * @param ans   数组
 * @param num   单个数的乘积
 * @param zeros 0的个数
 */
private void insert(int[] ans, int num, int zeros) {
    // 索引
    int index = zeros;

    // 进位
    int carry = 0;

    // 被加数
    char[] chs = Integer.toString(num).toCharArray();

    // 从后往前遍历相加
    for (int i = chs.length - 1; i >= 0; i--) {
        int indexNum = chs[i] - '0' + ans[index] + carry;

        carry = indexNum / 10;

        ans[index++] = indexNum % 10;
    }

    // 进位
    while (carry > 0) {
        int indexNum = ans[index] + carry;

        carry = indexNum / 10;

        ans[index++] = indexNum % 10;
    }
}
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

# Review

# Tip

  • EditTextclearFocus()方法无效 [1] (opens new window)clearFocus并不是真的清除焦点,而是在整个布局中遍历获取focusInTouchModetrueView,如果EditText为第一个,就又重新设置了焦点,陷入了死循环,所以才会看上去无效,解决方法只需要将EditText之前的View设置如下属性:
    android:focusableInTouchMode="true"
    
    1
  • 码率、分辨率、帧率 [2] (opens new window)
    • 码率:指图像的精密度,像素的个数
    • 分辨率:期望的压缩后视频的大小
    • 帧率:每秒显示帧数
  • adb常用命令:
    • adb devices:列出所有已连接设备
    • adb tcpip 5555:设置目标设备以监听端口5555上的TCP/IP连接
    • adb connect host[:port]:通过TCP/IP连接到设备,如果您未指定端口,则使用默认端口5555
    • adb disconnect [host | host:port]:断开与在指定端口上运行的指定TCP/IP设备的连接
    • adb kill-server:终止adb服务器
    • adb install path_to_apk:安装APK
    • adb pull remote local:从设备中复制某个文件或目录(及其子目录)
    • adb push local remote:将某个文件或目录(及其子目录)复制到某个设备
    • adb shell:进入shell
      • am:调用Activity管理器
      • pm:调用软件包管理器
  • Toolbar内部左侧始终有一段空白,无法填充,只需 [3] (opens new window)
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    
    1
    2
  • 利用BitmapRegionDecoder可以实现加载大图

# Share

暂无内容

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