08 2021 档案

摘要:Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [3,2,1] Follow up: Recursive 阅读全文
posted @ 2021-08-31 21:26 sherry001
摘要:二叉树的中序遍历。 中序遍历我记为 左 - 中- 右。 Inorder (Left, Root, Right) : 4 2 5 1 3 树的遍历大部分都是可以给出迭代和递归两种做法的,两种做法的时间和空间复杂度一样,时间都是O(n),空间都是O(h)。 递归实现: class Solution { 阅读全文
posted @ 2021-08-31 21:26 sherry001
摘要:问题一: 安排最多的会议 会议包括开始时间和结束时间贪心法:准备一个优先队列(或是一个按结束时间排序的数组),一个时间节点(表示上一个会议结束的时间)初始设置为0遍历如果开始时间大于等于时间节点,则能能安排的会议数+1 public class BestArrange { public static 阅读全文
posted @ 2021-08-31 21:24 sherry001
摘要:Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] Follow up: Recursive s 阅读全文
posted @ 2021-08-31 21:24 sherry001
摘要:Given the head of a linked list, return the list after sorting it in ascending order. Follow up: Can you sort the linked list in O(n logn) time and O( 阅读全文
posted @ 2021-08-31 21:24 sherry001
摘要:先来看最多的线段重合数问题,给出一组线段集合,求最大重合线段数 求解过程: 把一个线段生成一个对象 开始位置start 结束位置end 选按开始位置排序 [1,7] [1,4] [1,9] [2,13] [5,10] 再搞一个有序表(按结束位置排序) 用TreeMap,TreeSet,或Priori 阅读全文
posted @ 2021-08-30 18:24 sherry001
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two 阅读全文
posted @ 2021-08-30 11:42 sherry001
摘要:Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) Initia 阅读全文
posted @ 2021-08-30 10:50 sherry001
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 阅读全文
posted @ 2021-08-30 09:43 sherry001
摘要:Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists. E 阅读全文
posted @ 2021-08-29 17:22 sherry001
摘要:Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the 阅读全文
posted @ 2021-08-29 16:09 sherry001
摘要:Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Example 阅读全文
posted @ 2021-08-29 16:06 sherry001
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use 阅读全文
posted @ 2021-08-29 12:37 sherry001
摘要:Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the posi 阅读全文
posted @ 2021-08-29 12:16 sherry001
摘要:Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should p 阅读全文
posted @ 2021-08-29 09:14 sherry001
摘要:给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。 示例 1: 输入:head = [1,2,6,3,4,5,6], val = 6输出:[1,2,3,4,5] 解题思路: 借助dummy node。 这个题用 阅读全文
posted @ 2021-08-28 18:59 sherry001
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2021-08-28 13:35 sherry001
摘要:给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] /** * Definition for singly-linked list. * public class ListNode { * i 阅读全文
posted @ 2021-08-28 11:32 sherry001