09 2020 档案
摘要:给定一个二叉树,返回它的 后序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [3,2,1]进阶: 递归算法很简单,你可以通过迭代算法完成吗? /** * Definition for a binary tree node. * struct TreeNode { *
阅读全文
摘要:现在你总共有 n 门课需要选,记为 0 到 n-1。 在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量以及它们的先决条件,返回你为了学完所有课程所安排的学习顺序。 可能会有多个正确的顺序,你只要返回一种就可以
阅读全文
摘要:你这个学期必须选修 numCourse 门课程,记为 0 到 numCourse-1 。 在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们:[0,1] 给定课程总量以及它们的先决条件,请你判断是否可能完成所有课程的学习? 示例 1: 输
阅读全文
摘要:#include <bits/stdc++.h> // 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前。 //1.动态规划求解 //2.由题意可得最高位的数值是2 //3.以剩余为使用的元素作为基准开始进行动态规划的递推 //4.注意要在运算的过程中取余(在运算的过程中取余和得到最后的
阅读全文
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example,
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; //不是递增的话就删掉,然后重新计算一次 int getMaxArea(vector<int> &vec) { stack<int> s; int max_area = 0; int i=0; int tp,
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; int num[1005];//O(n2)的时间复杂度 int main(){ int n; cin>>n; for(int i=1;i<=n;++i){ cin>>num[i]; } int temp_mi
阅读全文
摘要:#include<bits/stdc++.h> //注意学会使用结构体和相应的排序,直接记录好相应的编号 //避免使用堆这种数据结构来减少时间复杂度,编起来太复杂 using namespace std; const int maxn =2005; int n,x,y; struct node{ i
阅读全文
摘要:给你一个字符串 s ,请你拆分该字符串,并返回拆分后唯一子字符串的最大数目。 字符串 s 拆分后可以得到若干 非空子字符串 ,这些子字符串连接后应当能够还原为原字符串。但是拆分出来的每个子字符串都必须是 唯一的 。 注意:子字符串 是字符串中的一个连续字符序列。 示例 1: 输入:s = "abab
阅读全文
摘要:在本问题中,有根树指满足以下条件的有向图。该树只有一个根节点,所有其他节点都是该根节点的后继。每一个节点只有一个父节点,除了根节点没有父节点。 输入一个有向图,该图由一个有着N个节点 (节点值不重复1, 2, ..., N) 的树及一条附加的边构成。附加的边的两个顶点包含在1到N中间,这条附加的边不
阅读全文
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example
阅读全文
摘要:here are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v i
阅读全文
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文
摘要:在一个操场上摆放着一排 NN 堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的 22 堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。 试设计一个算法,计算出将 NN 堆石子合并成一堆的最小得分。 输入格式 第一行一个整数 NN。 接下来 NN 行,第 ii 行一个整数 a_i
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all
阅读全文
摘要:1.若测试数据 n取到10^9数量级,则一般应该采用O(logn)或者O(根号n)的算法,一般O(n)的算法只能支持到10^8数量级 2.注意使用动态规划,并利用矩阵加速来加快运行时间。
阅读全文
摘要:Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and t
阅读全文

浙公网安备 33010602011771号