摘要: 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 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 二叉树的中序遍历。 中序遍历我记为 左 - 中- 右。 Inorder (Left, Root, Right) : 4 2 5 1 3 树的遍历大部分都是可以给出迭代和递归两种做法的,两种做法的时间和空间复杂度一样,时间都是O(n),空间都是O(h)。 递归实现: class Solution { 阅读全文
posted @ 2021-08-31 21:26 sherry001 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 问题一: 安排最多的会议 会议包括开始时间和结束时间贪心法:准备一个优先队列(或是一个按结束时间排序的数组),一个时间节点(表示上一个会议结束的时间)初始设置为0遍历如果开始时间大于等于时间节点,则能能安排的会议数+1 public class BestArrange { public static 阅读全文
posted @ 2021-08-31 21:24 sherry001 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(21) 评论(0) 推荐(0) 编辑