自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

descire

技术分享

  • 博客(41)
  • 收藏
  • 关注

原创 646. Maximum Length of Pair Chain [JavaScript]

一、解题思路  这是一道典型的DP类题目,但是对于这个给定的数组需要进行排序,不然很难总结出dp的递推公式。  对数组排序之后,那么就按照DP的套路依次进行下去:  第一步,定义状态 dp[i] 表示从0 ~ i 最长 pair chain  第二步,边界条件 dp[0] = 0 dp[1] = 1  第三步,递推公式 dp[i] = pairs[i][0] >...

2019-01-23 13:58:23 159

原创 712. Minimum ASCII Delete Sum for Two Strings [JavaScript]

一、题目  Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.二、题目大意  给定两个字符串s1,s2,找到删除字符的最低ascii和,使两个字符串相等。三、解题思路  这是一道典型的动态规划题目:1、定义状态 dp[i][j] 表示...

2019-01-22 09:59:42 86

原创 844. Backspace String Compare [JavaScript]

一、题目  Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.二、题目大意  给定两个字符串s和t,当它们都被输入空文本编辑器时,返回是否相等。#表示退格字符。三、解题思路  采用栈的方...

2019-01-21 00:40:13 156

原创 338. Counting Bits [JavaScript]

一、题目  Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.二、题目大意  给定一个非负整数nu...

2019-01-20 18:06:33 203

原创 968. Binary Tree Cameras [JavaScript]

一、题目  Given a binary tree, we install cameras on the nodes of the tree.  Each camera at a node can monitor its parent, itself, and its immediate children.  Calculate the minimum number of cameras n...

2019-01-18 09:54:18 185

原创 124. Binary Tree Maximum Path Sum [JavaScript]

一、题目  Given a non-empty binary tree, find the maximum path sum.  For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child c...

2019-01-17 22:23:54 126

原创 105. Construct Binary Tree from Preorder and Inorder Traversal [JavaScript]

一、题目  Given preorder and inorder traversal of a tree, construct the binary tree.  You may assume that duplicates do not exist in the tree.二、题目大意  根据前序遍历序列和中序遍历序列构建二叉树,二叉树中每个节点的值都不相同。三、解题思路  首先要知...

2019-01-17 17:48:02 148

原创 450. Delete Node in a BST [JavaScript]

一、题目  Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.  Basically, the deletion can be div...

2019-01-16 14:45:22 87

原创 113. Path Sum II [JavaScript]

一、题目  Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.二、题目大意  给定一个二叉树和一个和,找到所有根到叶路径,其中每个路径的和等于给定的和。三、解题思路  采用递归遍历二叉树的方法,在递归的过程中,记录当前节点所对应的和值以...

2019-01-16 09:53:50 128

原创 103. Binary Tree Zigzag Level Order Traversal [JavaScript]

一、题目  Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).二、题目大意  给定一个二叉树,返回其节点值...

2019-01-16 09:53:44 126

原创 玩转Koa -- koa-bodyparser原理解析

一、前置知识  在理解koa-bodyparser原理之前,首先需要了解部分HTTP相关的知识。1、报文主体  HTTP报文主要分为请求报文和响应报文,koa-bodyparser主要针对请求报文的处理。  请求报文主要由以下三个部分组成:报文头部空行报文主体  而koa-bodyparser中的body指的就是请求报文中的报文主体部分。2、服务器端获取报文主体流程  HT...

2019-01-16 09:40:20 6784

原创 129. Sum Root to Leaf Numbers [JavaScript]

一、题目  Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.  An example is the root-to-leaf path 1->2->3 which represents the number 123. Find ...

2019-01-15 14:26:20 67

原创 971. Flip Binary Tree To Match Preorder Traversal [JavaScript]

一、题目  Given a binary tree with N nodes, each node has a different value from {1, …, N}.  A node in this binary tree can be flipped by swapping the left child and the right child of that node.  Cons...

2019-01-15 10:38:45 123

原创 652. Find Duplicate Subtrees [JavaScript]

一、题目  Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.  Two trees are duplicate if they have the sam...

2019-01-15 10:03:11 133

原创 863. All Nodes Distance K in Binary Tree [JavaScript]

一、题目  We are given a binary tree (with root node root), a target node, and an integer value K.  Return a list of the values of all nodes that have a distance K from the target node. The answer can ...

2019-01-14 14:08:21 163 2

原创 102. Binary Tree Level Order Traversal [JavaScript]

一、题目  Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).二、题目大意  层级遍历二叉树。三、解题思路  这里采用队列的方式解决,同样也可以采用递归的方式。代码实现const levelOrder ...

2019-01-14 10:24:23 249 1

原创 623. Add One Row to Tree [JavaScript]

一、题目  Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.  The adding rule is: given a positive ...

2019-01-13 22:55:43 129

原创 337. House Robber III [JavaScript]

一、题目  The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After...

2019-01-13 22:55:14 314

原创 JavaScript刷LeetCode -- 230. Kth Smallest Element in a BST [Medium]

一、题目  Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.二、题目大意  找出二叉搜索树中第K小的元素。三、解题思路  中序遍历二叉搜索树。四、代码实现const kthSmallest1 = (root, k) => { con...

2019-01-11 15:18:40 201

原创 508. Most Frequent Subtree Sum [JavaScript]

一、题目  Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (...

2019-01-11 11:41:27 89

原创 865. Smallest Subtree with all the Deepest Nodes [JavaScript]

一、题目  Given a binary tree rooted at root, the depth of each node is the shortest distance to the root.  A node is deepest if it has the largest depth possible among any node in the entire tree.  Th...

2019-01-11 10:54:44 182

原创 515. Find Largest Value in Each Tree Row [JavaScript]

一、题目  You need to find the largest value in each row of a binary tree.二、题目大意  找出二叉树每层节点的最大值。三、解题思路  采用队列分层遍历二叉树。四、代码实现const largestValues = root => { const ans = [] if (!root) { retu...

2019-01-10 14:23:15 135

原创 889. Construct Binary Tree from Preorder and Postorder Traversal [JavaScript]

一、题目  Return any binary tree that matches the given preorder and postorder traversals.  Values in the traversals pre and post are distinct positive integers.二、题目大意  根据二叉树的前序和后序序列构建二叉树。(并且序列中无重复的元素...

2019-01-10 12:24:18 109

原创 513. Find Bottom Left Tree Value [JavaScript]

一、题目  Given a binary tree, find the leftmost value in the last row of the tree.二、题目大意  给出二叉树最后一行中最左边的节点值。三、解题思路  采用队列分层遍历二叉树。四、代码实现const findBottomLeftValue = (root) => { if (!root) { ...

2019-01-10 12:23:38 60

原创 951. Flip Equivalent Binary Trees [JavaScript]

一、题目  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 X is flip equivalent to a binary tree Y if and only ...

2019-01-09 15:27:46 187

原创 701. Insert into a Binary Search Tree [JavaScript]

一、题目  Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed ...

2019-01-09 09:35:45 84

原创 894. All Possible Full Binary Trees [JavaScript]

一、题目  A full binary tree is a binary tree where each node has exactly 0 or 2 children.  Return a list of all possible full binary trees with N nodes. Each element of the answer is the root node of ...

2019-01-08 23:39:17 152

原创 687. Longest Univalue Path [JavaScript]

一、题目  Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.二、题目大意  从二叉树中找出一条节点值相同的最长路径。三、解题思路  这...

2019-01-08 23:38:56 84

原创 112. Path Sum [JavaScript]

一、题目  Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.二、题目大意  判断二叉树中是否存在从根节点到叶子节点和值为sum的路径。三、解题思...

2019-01-08 12:21:04 113

原创 501. Find Mode in Binary Search Tree [JavaScript]

一、题目  Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.  Assume a BST is defined as follows:The left subtree of a node...

2019-01-08 11:44:18 149

原创 437. Path Sum III [JavaScript]

一、题目  You are given a binary tree in which each node contains an integer value.  Find the number of paths that sum to a given value.  The path does not need to start or end at the root or a leaf, b...

2019-01-07 09:58:43 133

原创 235. Lowest Common Ancestor of a Binary Search Tree [JavaScript]

一、题目  Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.  According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined ...

2019-01-04 17:26:01 190

原创 671. Second Minimum Node In a Binary Tree [JavaScript]

一、题目  Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this no...

2019-01-04 16:35:02 158

原创 107. Binary Tree Level Order Traversal II [JavaScript]

一、题目  Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root)。二、题目大意  给定二叉树,返回其节点值的自下而上的顺序遍历。(即从左到右,从叶到根逐级排列...

2019-01-04 16:07:20 100

原创 653. Two Sum IV - Input is a BST [JavaScript]

一、题目  Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.二、题目大意  二叉搜索树中是否存在两个元素的值为k。三、解题思路  递归遍历二叉...

2019-01-04 10:14:36 134

原创 637. Average of Levels in Binary Tree [JavaScript]

一、题目  Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.二、题目大意  计算二叉树每一层节点的平均值。三、解题思路  递归分层遍历二叉树。四、代码实现const averageOfLevels = root =&gt...

2019-01-03 21:05:12 114

原创 669. Trim a Binary Search Tree [JavaScript]

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

2019-01-03 20:49:39 88

原创 897. Increasing Order Search Tree [JavaScript]

一、题目  Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.二、题目大意  给定一棵树,按顺序重新排列树,...

2019-01-03 18:14:42 184

原创 95. Unique Binary Search Trees II [JavaScript]

一、题目  Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.二、题目大意  给定一个整数n,请给出由1~n序列组成的二叉搜索树的所有情况。三、解题思路  这道题与96 Unique Binary Search Trees不同点在...

2019-01-03 17:40:42 135

原创 96. Unique Binary Search Trees [JavaScript]

一、题目  Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?二、题目大意  给定一个整数n,通过1~n的序列可以构建多少颗不同的二叉搜索树。三、解题思路  这道题目采用动态规划解决,提到动态规划首先需要定义状态:dp[n]表示n个节点可以构建的二叉搜索树的数...

2019-01-03 00:23:52 113

空空如也

空空如也

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

TA关注的人

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