自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

原创 在有序数字中寻找和为k的两个数 O(n)

思路:分别在有序数字串的两头向中间遍历 bool findTarget(vector<int> &nums,int k) { for(i=0,j=nums.size()-1;i<j;){ if(nums[i]+nums[j]==k)return true; (nums[i]+nums[j]&...

2019-05-19 21:54:36 453

原创 865. Smallest Subtree with all the Deepest Nodes(‘找小弟’思想)

problem:Given a binary tree rooted atroot, thedepthof each node is the shortest distance to the root.A node isdeepestif it has the largest depth possible amongany node in theentire tree....

2019-05-19 21:46:39 127

原创 951. Flip Equivalent Binary Trees(左右交叉走思想)

problem:For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.A binary tree Xisflip equivalentto a binary tree Y if and on...

2019-05-17 20:03:22 231

原创 1026. Maximum Difference Between Node and Ancestor(递归+记录最大最小值)

problem:Given therootof a binary tree, find the maximum valueVfor which there existsdifferentnodesAandBwhereV = |A.val - B.val|andAis an ancestor ofB.(A node A is an ancestor of B ...

2019-05-17 19:49:26 352

原创 889. Construct Binary Tree from Preorder and Postorder Traversal (用stack构建树)

Return any binary tree that matches the given preorder and postorder traversals.Values in the traversalspreandpostare distinctpositive integers.Example 1:Input: pre = [1,2,4,5,3,6,7], ...

2019-05-17 11:34:52 86

原创 669. Trim a Binary Search Tree(‘找小弟’思想)

problem:Given a binary search tree and the lowest and highest boundaries asLandR, trim the tree so that all its elements lies in[L, R](R >= L). You might need to change the root of the tree...

2019-05-17 11:13:57 93

原创 872. Leaf-Similar Trees(迭代法配合stack获取所有叶子结点)

problem:Consider all the leaves of a binary tree. Fromleft to right order, the values of thoseleaves form aleaf value sequence.For example, in the given tree above, the leaf value sequence ...

2019-05-17 10:51:51 107

原创 1008. Construct Binary Search Tree from Preorder Traversal(lower and upper)

Return the root node of a binarysearchtree that matches the givenpreordertraversal.(Recall that a binary search treeis a binary tree where for everynode, any descendant ofnode.lefthas a val...

2019-05-13 15:02:25 92

原创 1028. Recover a Tree From Preorder Traversal(用stack构建树)

problem:We run apreorderdepth first search on therootof a binary tree.At each node in this traversal, we outputDdashes (whereDis thedepthof this node), then we output the value of this ...

2019-05-13 14:37:09 297

原创 617. Merge Two Binary Trees(‘抢小弟’思想)

problem:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new ...

2019-05-12 22:35:06 88

原创 979. Distribute Coins in Binary Tree

Problem:Given therootof a binary tree withNnodes, eachnodein the tree hasnode.valcoins, and there areNcoins total.In one move, we may choose two adjacent nodes and move one coin from on...

2019-05-12 22:02:53 116

原创 Maximum Binary Tree

Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array. The left subtree is the maximum tree constructed ...

2019-05-10 11:45:54 125

原创 My Calendar

leetcode problem:My Calendar1Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method,book(...

2019-05-10 11:21:54 1069

原创 856. 括号的分数

problem:给定一个平衡括号字符串S,按下述规则计算该字符串的分数:()得 1 分。 AB得A + B分,其中 A 和 B 是平衡括号字符串。 (A)得2 * A分,其中 A 是平衡括号字符串。示例 1:输入: "()"输出: 1示例 2:输入: "(())"输出: 2示例3:输入: "()()"输出: 2示例...

2019-05-04 09:32:01 85

原创 739.每日温度

题目:根据每日气温列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高的天数。如果之后都不会升高,请输入0来代替。例如,给定一个列表temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是[1, 1, 4, 2, 1, 1, 0, 0]。提示:气温列表长度的范围是[1, 30000]。每个气温的值的都是...

2019-05-03 20:13:09 182

原创 94. 二叉树的中序遍历(迭代)

用栈记录走过的位置,当遇到NULL结点时,用栈pop进行回溯//回溯到父节点后,应该马上进入父结点的 右结点,这样就可以避免重复进入左结点(相当于递归回到当前层的时候,只是继续执行上次剩下没执行的语句,而不是把当前层的所有代码都执行一遍)/** * Definition for a binary tree node. * struct TreeNode { * int...

2019-05-02 22:13:01 459

原创 1021. 删除最外层的括号

思路:stack在两次empty之间,括号存在闭合,那么我们可以分别记录两次empty时的索引,最后用索引提取字符串class Solution {public: string removeOuterParentheses(string str) { string ans=""; stack<char> s; i...

2019-05-02 18:33:25 216

原创 铁轨(6-2)

判断出栈顺序是否正确:如果与栈顶相同#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<stack>using namespace std;#define maxn 100int main() { int n; int s[maxn],t[maxn];//入栈元素s , 判断元素t i...

2019-05-02 16:46:42 63

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除