
LeetCode
liuxiaocs7
这个作者很懒,什么都没留下…
展开
-
LeetCode 0367 Valid Perfect Square【验证完美平方数】
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Output: trueExample 2:Input: 14Output: false题意判断指定的数是否是平方数原创 2020-05-09 15:52:27 · 296 阅读 · 0 评论 -
LeetCode 1232 Check If It Is a Straight Line【 缀点成线,数学】
题目链接 1232. Check If It Is a Straight Line | 1232. 缀点成线You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a s...原创 2020-05-08 15:30:37 · 282 阅读 · 0 评论 -
LeetCode 0383 Ransom Note【赎金信,哈希】
题目链接 383. Ransom Note |Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constru...原创 2020-05-08 14:59:23 · 232 阅读 · 0 评论 -
LeetCode 0771 Jewels and Stones【宝石与石头,哈希】
题目链接 771. Jewels and Stones |You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You ...原创 2020-05-08 14:47:12 · 252 阅读 · 0 评论 -
LeetCode 0278 First Bad Version【第一个错误的版本,二分】
题目链接 278.First Bad Version |You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each ...原创 2020-05-08 14:24:36 · 189 阅读 · 0 评论 -
LeetCode 0589 N-ary Tree Preorder Traversal【N叉树,DFS】
Given an n-ary tree, return the preorder traversal of its nodes’ values.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null va...原创 2020-04-26 23:22:08 · 474 阅读 · 0 评论 -
LeetCode 0104 Maximum Depth of Binary Tree 【二叉树】
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children....原创 2020-04-26 23:21:58 · 193 阅读 · 0 评论 -
LeetCode 0112 Path Sum 【二叉树】
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.Note: A leaf is a node with no children.Example:G...原创 2020-04-26 23:21:34 · 207 阅读 · 0 评论 -
LeetCode 0116 Populating Next Right Pointers in Each Node【二叉树,BFS】
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; No...原创 2020-04-26 23:21:25 · 172 阅读 · 0 评论 -
LeetCode 0236.Lowest Common Ancestor of a Binary Tree【二叉树】
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p a...原创 2020-04-26 23:21:17 · 300 阅读 · 0 评论 -
LeetCode 0117 Populating Next Right Pointers in Each Node II【二叉树,BFS】
Given a binary treestruct Node { int val; Node *left; Node *right; Node *next;}Populate each next pointer to point to its next right node. If there is no next right node, the next pointer ...原创 2020-04-26 23:21:03 · 175 阅读 · 0 评论 -
LeetCode 0235 Lowest Common Ancestor of a Binary Search Tree【二叉搜索树,LCA】
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 between t...原创 2020-04-26 23:19:58 · 269 阅读 · 0 评论 -
LeetCode 0404 Sum of Left Leaves【左边叶节点数量,二叉树,递归】
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24....原创 2020-04-26 23:19:13 · 173 阅读 · 0 评论 -
LeetCode 0111 Minimum Depth of Binary Tree【二叉树,最小深度,递归】
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children....原创 2020-04-26 23:18:52 · 157 阅读 · 0 评论 -
LeetCode 0101 Symmetric Tree【二叉树,树的对称,递归】
题目链接 LeetCode | 力扣Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / ...原创 2020-04-25 13:12:27 · 183 阅读 · 0 评论 -
LeetCode 0572 Subtree of Another Tree【二叉树,递归】
题目链接 LeetCode | 力扣Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s...原创 2020-04-25 13:09:41 · 171 阅读 · 0 评论 -
LeetCode 0437 Path Sum III【二叉树,递归】
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, but it must ...原创 2020-04-25 12:48:41 · 184 阅读 · 0 评论 -
LeetCode 0112 Path Sum【二叉树,DFS,递归】
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.Note: A leaf is a node with no children.Example:G...原创 2020-04-25 12:30:42 · 194 阅读 · 0 评论 -
LeetCode 0226 Invert Binary Tree【树,翻转二叉树,DFS,递归】
题目链接 LeetCode | [力扣]Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspir...原创 2020-04-25 12:02:51 · 150 阅读 · 0 评论 -
LeetCode 0543 Diameter of Binary Tree【二叉树直径,DFS,递归】
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n...原创 2020-04-25 11:55:26 · 186 阅读 · 0 评论 -
LeetCode 0104 Maximum Depth of Binary Tree【树的深度,DFS,递归】
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children....原创 2020-04-25 11:38:04 · 160 阅读 · 0 评论 -
LeetCode 0110 Balanced Binary Tree【平衡二叉树,dfs】
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the left and right subtrees of every node differ in heig...原创 2020-04-25 11:24:00 · 201 阅读 · 0 评论 -
LeetCode 0108 Convert Sorted Array to Binary Search Tree【二叉搜索树】
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the ...原创 2020-04-25 11:22:58 · 154 阅读 · 0 评论 -
LeetCode 0703 Kth Largest Element in a Stream【优先队列,堆】
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.Your KthLargest class will have a constructor whi...原创 2020-04-26 23:19:50 · 147 阅读 · 0 评论 -
LeetCode 0701 Insert into a Binary Search Tree【二叉搜索树插入】
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 that th...原创 2020-04-24 16:02:01 · 175 阅读 · 0 评论 -
LeetCode 0700 Search in a Binary Search Tree【二叉搜索树】
Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node’s value equals the given value. Return the subtree rooted with that node. If such node...原创 2020-04-24 15:58:30 · 168 阅读 · 0 评论 -
LeetCode 0173 Binary Search Tree Iterator【二叉搜索树】
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Example:BSTIterat...原创 2020-04-24 15:54:10 · 159 阅读 · 0 评论 -
LeetCode 0098 Validate Binary Search Tree【二叉搜索树】
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.The ri...原创 2020-04-24 15:40:58 · 227 阅读 · 0 评论 -
LeetCode 0516 Longest Palindromic Subsequence【DP,最长回文子序列】
Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palindromic su...原创 2020-04-22 20:58:01 · 185 阅读 · 0 评论 -
LeetCode 0053. Maximum Subarray【DP,最大子序和】
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanatio...原创 2020-04-22 19:32:17 · 228 阅读 · 0 评论 -
LeetCode 0120 Triangle【DP,数塔问题】
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7]...原创 2020-04-22 19:29:37 · 322 阅读 · 0 评论 -
LeetCode 0300 Longest Increasing Subsequence【DP,最长上升子序列LCS】
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101],...原创 2020-04-22 19:23:03 · 171 阅读 · 0 评论 -
LeetCode 0098 Validate Binary Search Tree【二叉搜索树】
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.The ri...原创 2020-04-21 22:19:10 · 218 阅读 · 0 评论 -
LeetCode 0429 N-ary Tree Level Order Traversal【N叉树,BFS】
Given an n-ary tree, return the level order traversal of its nodes’ values.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null...原创 2020-04-21 21:03:49 · 232 阅读 · 0 评论 -
LeetCode 0101 Symmetric Tree 【二叉树】
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But ...原创 2020-04-21 20:36:30 · 183 阅读 · 0 评论 -
LeetCode N-ray Tree [n叉树]
二叉树是一棵以根节点开始,每个节点含有不超过2个子节点的树。 让我们将这个定义扩展到N叉树。 一棵以根节点开始,每个节点不超过N个子节点的树,称为N叉树。前缀树,又称字典树( Trie), 就是一个常用的 N 叉树。遍历LeetCode589.N-ary Tree Preorder TraversalEasy590.N-ary Tree Postorder T...原创 2020-04-21 20:27:00 · 283 阅读 · 0 评论 -
LeetCode 0590 N-ary Tree Postorder Traversal【N叉树,DFS】
Given an n-ary tree, return the postorder traversal of its nodes’ values.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null v...原创 2020-04-26 23:22:01 · 462 阅读 · 0 评论 -
LeetCode 0559 Maximum Depth of N-ary Tree【N叉树,DFS】
Given a n-ary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Nary-Tree input serialization is represen...原创 2020-04-21 16:20:01 · 180 阅读 · 0 评论 -
LeetCode 1008 Construct Binary Search Tree from Preorder Traversal【二叉树,BST】
Return the root node of a binary search tree that matches the given preorder traversal.(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value...原创 2020-04-21 13:12:04 · 313 阅读 · 0 评论 -
LeetCode 0106. Construct Binary Tree from Inorder and Postorder Traversal【二叉树】
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, giveninorder = [9,3,15,20,7]postorder = [9,15,...原创 2020-04-21 13:00:35 · 144 阅读 · 0 评论