随笔分类 - 数据结构
摘要:title: "Uva 514 Rails" date: 2018 02 07T21:38:33+08:00 tags: ["栈"] categories: ["数据结构"] 题目 "原题链接" 分析 直接利用STL中的stack模仿栈的操作. 代码 c++ include "bits/stdc++
阅读全文
摘要:title: 04 树6 Complete Binary Search Tree(30 分) date: 2017 11 12 14:20:46 tags: 完全二叉树 二叉搜索树 categories: 数据结构 "题目链接" 题目大意 给出n个节点,构造一棵完全二叉搜索树。 最后按层次遍历输出这
阅读全文
摘要:设置链表数据结构 反转链表,且不占用额外空间 反转链表,返回反转后的结果,原链表不受影响 反转链表,返回翻转后的结果,原链表移到最后一个结点
阅读全文
摘要:题目 "题目链接" 分析 为二叉树结构添加一个 字段,表示搜索过程中是否走过,初始化为 。 根据第一个输入样例建立二叉树,设置一个全局的 ,根据后面的样例搜索。 1. 如果在搜索二叉树里没有找到符合的结点,则一定不能构成同样的二叉树。 2. 如果在搜索过程中经过 为`false`的结点,表示出错,不
阅读全文
摘要:题目 "链接" 分析 push是二叉树前序遍历的结果,pop是二叉树中序遍历的结果,所以这个题就是已知前序遍历和中序遍历,求后序遍历。 AC代码 cpp include "bits/stdc++.h" using namespace std; struct TreeNode { int left=
阅读全文
摘要:题目 分析 输入先给出结点的数量,把结点从0开始标号,每一行给出结点的左右两个子节点, 表示子节点不存在。 很容易分析出在子节点中没有出现的就是根节点,两个子节点都为空的是叶子节点 先建树,然后从root结点广度优先搜索,搜索到叶子节点就搜索,需要注意的是因为要求输出的顺序是从上到下、从左到右,因此
阅读全文
摘要:题目 02 线性结构2 一元多项式的乘法与加法运算(20 分) 设计函数分别求两个一元多项式的乘积与和。 输入格式: 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。 输出格式: 输出分2行,分别以指数
阅读全文
摘要:题目 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 分析 判断链表是否有环,采用快慢指针,如果相遇则表示有环 AC代码
阅读全文
摘要:题目 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can
阅读全文
摘要:原题 Given a singly linked list L: L0?L1?…?Ln 1?Ln, reorder it to: L0?Ln?L1?Ln 1?L2?Ln 2?… You must do this in place without altering the nodes' values.
阅读全文
摘要:原题 Given a binary tree, return the preorder traversal of its nodes' values. 分析 对二叉树进行先序遍历,即根节点 左子树 右子树 代码: 递归: 递归代码十分简单,建立一个vector作为返回的结果,现将根节点push进去,
阅读全文
摘要:__描述:__ Given a binary tree, return the postorder traversal of its nodes' values. 直接递归,按照 左子树 右子树 头结点的顺序 AC代码:
阅读全文
摘要:__描述:__ Sort a linked list using insertion sort. 使用插入排序对一个链表进行排序 普通的插入排序,时间复杂度O(n^2)
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity.
阅读全文
摘要:题目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integ...
阅读全文
摘要:题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down t...
阅读全文
