Java LinkedHashMap获取第一个元素和最后一个元素

获取LinkedHashMap中的头部元素(最早添加的元素):

时间复杂度O(1)

public <K, V> Entry<K, V> getHead(LinkedHashMap<K, V> map) {
    return map.entrySet().iterator().next();
}

获取LinkedHashMap中的末尾元素(最近添加的元素):

时间复杂度O(n)

public <K, V> Entry<K, V> getTail(LinkedHashMap<K, V> map) {
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    Entry<K, V> tail ...

继续阅读

[LeetCode]Smarking Algorithm Contest解题报告

Smarking Algorithm Contest是LeetCode举办的第九场正式周赛,共4道题目,比赛时长2.5小时。

比赛链接:https://leetcode.com/contest/smarking-algorithm-contest/

题解列表:

LeetCode 437. Path Sum III

LeetCode 438. Find All Anagrams in a String

LeetCode 439. Ternary Expression Parser

LeetCode 440. K-th Smallest in Lexicographical Order

年度归档