7 X丶

尚未进行身份认证

暂无相关描述

等级
TA的排名 9w+

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

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

2019-05-19 21:54:36

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

problem:Givenabinarytreerootedatroot,thedepthofeachnodeistheshortestdistancetotheroot.Anodeisdeepestifithasthelargestdepthpossibleamonganynodeintheentiretree....

2019-05-19 21:46:39

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

problem:ForabinarytreeT,wecandefineaflipoperationasfollows:chooseanynode,andswaptheleftandrightchildsubtrees.AbinarytreeXisflipequivalenttoabinarytreeYifandon...

2019-05-17 20:03:22

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

problem:Giventherootofabinarytree,findthemaximumvalueVforwhichthereexistsdifferentnodesAandBwhereV=|A.val-B.val|andAisanancestorofB.(AnodeAisanancestorofB...

2019-05-17 19:49:26

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

Returnanybinarytreethatmatchesthegivenpreorderandpostordertraversals.Valuesinthetraversalspreandpostaredistinctpositiveintegers.Example1:Input:pre=[1,2,4,5,3,6,7],...

2019-05-17 11:34:52

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

problem:GivenabinarysearchtreeandthelowestandhighestboundariesasLandR,trimthetreesothatallitselementsliesin[L,R](R>=L).Youmightneedtochangetherootofthetree...

2019-05-17 11:13:57

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

problem:Consideralltheleavesofabinarytree.Fromlefttorightorder,thevaluesofthoseleavesformaleafvaluesequence.Forexample,inthegiventreeabove,theleafvaluesequence...

2019-05-17 10:51:51

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

Returntherootnodeofabinarysearchtreethatmatchesthegivenpreordertraversal.(Recallthatabinarysearchtreeisabinarytreewhereforeverynode,anydescendantofnode.lefthasaval...

2019-05-13 15:02:25

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

problem:Werunapreorderdepthfirstsearchontherootofabinarytree.Ateachnodeinthistraversal,weoutputDdashes(whereDisthedepthofthisnode),thenweoutputthevalueofthis...

2019-05-13 14:37:09

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

problem:Giventwobinarytreesandimaginethatwhenyouputoneofthemtocovertheother,somenodesofthetwotreesareoverlappedwhiletheothersarenot.Youneedtomergethemintoanew...

2019-05-12 22:35:06

979. Distribute Coins in Binary Tree

Problem:GiventherootofabinarytreewithNnodes,eachnodeinthetreehasnode.valcoins,andthereareNcoinstotal.Inonemove,wemaychoosetwoadjacentnodesandmoveonecoinfromon...

2019-05-12 22:02:53

Maximum Binary Tree

Givenanintegerarraywithnoduplicates.Amaximumtreebuildingonthisarrayisdefinedasfollow:Therootisthemaximumnumberinthearray. Theleftsubtreeisthemaximumtreeconstructed...

2019-05-10 11:45:54

My Calendar

leetcodeproblem:MyCalendar1ImplementaMyCalendarclasstostoreyourevents.Aneweventcanbeaddedifaddingtheeventwillnotcauseadoublebooking.Yourclasswillhavethemethod,book(...

2019-05-10 11:21:54

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

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

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

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

2019-05-02 22:13:01

1021. 删除最外层的括号

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

2019-05-02 18:33:25

铁轨(6-2)

判断出栈顺序是否正确:如果与栈顶相同#define_CRT_SECURE_NO_WARNINGS#include<iostream>#include<stack>usingnamespacestd;#definemaxn100intmain(){ intn; ints[maxn],t[maxn];//入栈元素s,判断元素t i...

2019-05-02 16:46:42

DNN的BP推导

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

2019-04-30 13:34:33

最大子段和(分治法)

将长度为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

查看更多

勋章 我的勋章
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 勤写标兵Lv3
    勤写标兵Lv3
    授予每个自然周发布7篇到8篇原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。