# 第二十一周ARTS总结

# Algorithm

0ms | 100.00% Run time
34.2MB | 100.00% Memory

public ListNode swapPairs(ListNode head) {
    ListNode changedNode = new ListNode(-1);
    changedNode.next = head;

    ListNode initNode = changedNode;

    while (changedNode.next != null) {
        ListNode next = changedNode.next;
        ListNode nnext = next.next;

        // 交换相邻两节点
        if (nnext != null) {
            changedNode.next = nnext;

            ListNode temp = nnext.next;
            nnext.next = next;
            next.next = temp;
        }

        changedNode = next;
    }

    return initNode.next;
}

static class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}
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

  • 关于处理Bitmap的一些规则
    • Never keep in memory more than you actually need
    • Scaling:利用inSampleSize、inDensity、inTargetDensity来显示图片,而不是复制一份图片做变换
    • Decode a specific region
    • Getting image size
    • ImageDecoder

# Share

暂无内容

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