跳至主要內容

146. LRU 缓存

T4mako算法哈希表链表双向链表小于 1 分钟

146. LRU 缓存

中等

题目open in new window

解法:遍历

class Solution {
    public ListNode sortList(ListNode head) {
		if(head == null) return null;
		ListNode node = head;
		ArrayList<Integer> list = new ArrayList<>();
		while(node != null) {
			list.add(node.val);
			node = node.next;
		}
		Object[] array = list.toArray();
		Arrays.sort(array);
		ListNode res = new ListNode((int)array[0]);
		ListNode idx = res;
		for (int i = 1; i < array.length; i++) {
			idx.next = new ListNode((int)array[i]);
			idx = idx.next;
		}
		return res;
    }
}
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.5