No.145 PostorderTraversal 二叉树的后序遍历

题目

  • 给定一个二叉树,返回它的 后序 遍历。
  • 进阶: 递归算法很简单,你可以通过迭代算法完成吗?

示例

  • 输入: [1,null,2,3]
  • 输出: [3,2,1]

思路

代码

No.146 LRUCache LRU缓存机制

题目

  • 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和 写入数据 put 。
  • 获取数据 get(key) - 如果密钥 (key) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1。
  • 写入数据 put(key, value) - 如果密钥不存在,则写入其数据值。当缓存容量达到上限时,它应该在写入新数据之前删除最近最少使用的数据值,从而为新的数据值留出空间。

  • 进阶:
  • 你是否可以在 O(1) 时间复杂度内完成这两种操作?

示例

  • LRUCache cache = new LRUCache( 2 /* 缓存容量 */ );
  • cache.put(1, 1);
  • cache.put(2, 2);
  • cache.get(1); // 返回 1
  • cache.put(3, 3); // 该操作会使得密钥 2 作废
  • cache.get(2); // 返回 -1 (未找到)
  • cache.put(4, 4); // 该操作会使得密钥 1 作废
  • cache.get(1); // 返回 -1 (未找到)
  • cache.get(3); // 返回 3
  • cache.get(4); // 返回 4

思路

代码

No.147 InsertionSortList 对链表进行插入排序

题目

  • 插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。
  • 每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。

  • 插入排序算法:
  • 插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。
  • 每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,并将其插入。
  • 重复直到所有输入数据插入完为止。

示例

  • 输入: 4->2->1->3
  • 输出: 1->2->3->4

  • 输入: -1->5->3->4->0
  • 输出: -1->0->3->4->5

思路

代码

LeetCode No.145,146,147的更多相关文章

  1. 【LeetCode】145. Binary Tree Postorder Traversal

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/binary-tree-pos ...

  2. 【LeetCode】145. 二叉树的后序遍历

    145. 二叉树的后序遍历 知识点:二叉树:递归:Morris遍历 题目描述 给定一个二叉树的根节点 root ,返回它的 后序 遍历. 示例 输入: [1,null,2,3] 1 \ 2 / 3 输 ...

  3. 【LeetCode】145. Binary Tree Postorder Traversal 解题报告 (C++&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  4. LeetCode: LRU Cache [146]

    [题目] Design and implement a data structure for Least Recently Used (LRU) cache. It should support th ...

  5. LeetCode OJ 145. Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...

  6. 【LeetCode】145. Binary Tree Postorder Traversal (3 solutions)

    Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' va ...

  7. Leetcode(145)-二叉树的后序遍历

    给定一个二叉树,返回它的 后序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [3,2,1] 思路:一开始编写二叉树后序遍历的程序,感觉定级为困难有点欠妥,确实,如果用 ...

  8. LeetCode题目解答

    LeetCode题目解答——Easy部分 Posted on 2014 年 11 月 3 日 by 四火 [Updated on 9/22/2017] 如今回头看来,里面很多做法都不是最佳的,有的从复 ...

  9. C++版-剑指offer 面试题6:重建二叉树(Leetcode105. Construct Binary Tree from Preorder and Inorder Traversal) 解题报告

    剑指offer 重建二叉树 提交网址: http://www.nowcoder.com/practice/8a19cbe657394eeaac2f6ea9b0f6fcf6?tpId=13&tq ...

随机推荐

  1. java项目提交到码云

    1.在码云上面创建一个新的项目,用于存放提交的项目内容 2.在需要共享的项目上右键-->team-->Share Project分享项目-->勾选 Use or create rep ...

  2. Python学习——enumerate

    enumerate(seq, start) seq -- 可遍历的序列      start -- 下标起始位置 seq = [11,22,33,44,55] for i in seq: print( ...

  3. .Net实现发送邮件功能

    public ActionResult AddPost()         {            ResponseResult result = new ResponseResult();     ...

  4. Spring中的注解——@nullable和@notnull

    @nullable和@nutNull 在写程序的时候你可以定义是否可为空指针.通过使用像@NotNull和@Nullable之类的annotation来声明一个方法是否是空指针安全的.现代的编译器.I ...

  5. Nginx系列p4:进程结构

    Nginx 有两种进程结构:单进程结构,多进程结构.本篇文章我们主要说多进程结构. 问:那为什么 Nginx 采用多进程结构,而不是多线程结构呢? 答:这是因为 Nginx 最核心的目的就是要保证高可 ...

  6. PAT Advanced 1143 Lowest Common Ancestor (30) [二叉查找树 LCA]

    题目 The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both ...

  7. 基于python的小波阈值去噪算法

    https://blog.csdn.net/alwaystry/article/details/52756051 发表于 2018-01-10 16:32:17 嵌入式设计应用 +关注 小波图像去噪原 ...

  8. 11. react 基础 使用charles 模拟接口数据

    charles参考文档 charles官网 模拟数据 模拟 axios 请求的数据 eg: 1. 编写 axios 请求 axios.get('/api/xxx') .then(()=>{ale ...

  9. Q2:Add Two Numbers

    2. Add Two Numbers 官方的链接:2. Add Two Numbers Description : You are given two non-empty linked lists r ...

  10. python3.4+Django+pymysql

    pip install Pymysql 修改app里面的__init__.py import pymysqlpymysql.install_as_MySQLdb()