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

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

2019-05-19 21:54:36

阅读数 70

评论数 0

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 ...

2019-05-19 21:46:39

阅读数 38

评论数 0

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...

2019-05-17 20:03:22

阅读数 19

评论数 0

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 o...

2019-05-17 19:49:26

阅读数 48

评论数 0

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. ...

2019-05-17 11:34:52

阅读数 14

评论数 0

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 >= ...

2019-05-17 11:13:57

阅读数 15

评论数 0

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 ...

2019-05-17 10:51:51

阅读数 18

评论数 0

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 ever...

2019-05-13 15:02:25

阅读数 16

评论数 0

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 ...

2019-05-13 14:37:09

阅读数 27

评论数 0

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 o...

2019-05-12 22:35:06

阅读数 12

评论数 0

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 ...

2019-05-12 22:02:53

阅读数 19

评论数 0

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. ...

2019-05-10 11:45:54

阅读数 16

评论数 0

My Calendar

leetcode problem:My Calendar1 Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double ...

2019-05-10 11:21:54

阅读数 17

评论数 0

856. 括号的分数

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

2019-05-04 09:32:01

阅读数 11

评论数 0

739.每日温度

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

2019-05-03 20:13:09

阅读数 18

评论数 0

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

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

2019-05-02 22:13:01

阅读数 39

评论数 0

1021. 删除最外层的括号

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

2019-05-02 18:33:25

阅读数 63

评论数 0

铁轨(6-2)

判断出栈顺序是否正确:如果与栈顶相同 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<stack> using namespace std; #define max...

2019-05-02 16:46:42

阅读数 11

评论数 0

DNN的BP推导

向前传播: 第一层 第二层 第三层 计算代价: 反向传播: 这是一个求偏导数的线路图 我们会发现,这都是有规律的: 每一列都是一样的,也就是我们可以通过从结果J反向求偏导数,累积偏导数来反向递推计算每一层的和 ...

2019-04-30 13:34:33

阅读数 25

评论数 0

最大子段和(分治法)

将长度为n的序列L划分成两个子序列,即 L(1,n/2) 和 L(n/2 + 1 ,n) 会出现3种情况: ① max{ L(1,n) }=max{ L(1,n/2)} ② max{ L(1,n) }=max{ L(n/2 + 1 ,n) } ③max{ L(1,n) } = 且 求...

2019-04-09 13:59:44

阅读数 109

评论数 0

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