diff --git a/notes/Java 容器.md b/notes/Java 容器.md index 82e4e0e6..8c79de2c 100644 --- a/notes/Java 容器.md +++ b/notes/Java 容器.md @@ -291,8 +291,6 @@ transient Entry[] table; JDK 1.8 使用 Node 类型存储一个键值对,它依然继承自 Entry,因此可以按照上面的存储结构来理解。 -需要注意的是,Key 类型为 final,这意味着它不可改变,因此每个桶的链表采用头插法实现,也就是说新节点需要只能在链表头部插入。 - ```java static class Node implements Map.Entry { final int hash; @@ -347,9 +345,9 @@ map.put("K3", "V3"); - 新建一个 HashMap,默认大小为 16; - 插入 <K1,V1> 键值对,先计算 K1 的 hashCode 为 115,使用除留余数法得到所在的桶下标 115%16=3。 - 插入 <K2,V2> 键值对,先计算 K2 的 hashCode 为 118,使用除留余数法得到所在的桶下标 118%16=6。 -- 插入 <K3,V3> 键值对,先计算 K3 的 hashCode 为 118,使用除留余数法得到所在的桶下标 118%16=6,它需要插在 <K2,V2> 之前。 +- 插入 <K3,V3> 键值对,先计算 K3 的 hashCode 为 118,使用除留余数法得到所在的桶下标 118%16=6,插在 <K2,V2> 后面。 -

+

查找需要分成两步进行: diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index 0d5defcb..72bdb5e5 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -3013,7 +3013,7 @@ Only two moves are needed (remember each move increments or decrements one eleme **解法 1** -先排序,时间复杂度:O(NlgN) +先排序,时间复杂度:O(NlogN) ```java public int minMoves2(int[] nums) { @@ -3031,7 +3031,7 @@ public int minMoves2(int[] nums) { **解法 2** -使用快速排序找到中位数,时间复杂度 O(N) +使用快速选择找到中位数,时间复杂度 O(N) ```java public int minMoves2(int[] nums) { diff --git a/pics/07903a31-0fb3-45fc-86f5-26f0b28fa4e7.png b/pics/07903a31-0fb3-45fc-86f5-26f0b28fa4e7.png new file mode 100644 index 00000000..40573164 Binary files /dev/null and b/pics/07903a31-0fb3-45fc-86f5-26f0b28fa4e7.png differ