![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
想吃锅包肉哇
这个作者很懒,什么都没留下…
展开
-
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.给定一个二叉树,求出它的最小深度,最小深度是从根节点到最近的叶子节...原创 2019-05-08 10:56:33 · 78 阅读 · 0 评论 -
evaluate-reverse-polish-notation
【题目描述】Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, , /. Each operand may be an integer or another expression.Some examples: [“2”, “1”, “+”, “3”...原创 2019-05-08 11:13:29 · 101 阅读 · 0 评论 -
max-points-on-a-line
【题目描述】Given n points on a 2D plane, find the maximum number of points that lie on the same straight line给定二维平面上的n个点,找到位于同一直线上的最大点数。【解题思路】暴力求解:两两连线,判断其他的点有没有在这条线上,并统计在同一条线上点的个数,最后取最大的。(思路2:通过判断斜率来判断...原创 2019-05-08 11:34:13 · 108 阅读 · 0 评论 -
sort-list
【题目描述】Sort a linked list in O(n log n) time using constant space complexity.链表排序【解题思路】因为题目要求复杂度为O(nlogn),故可以考虑归并排序的思想。归并排序的一般步骤为:1)将待排序数组(链表)取中点并一分为二;2)递归地对左半部分进行归并排序;3)递归地对右半部分进行归并排序;4)将两个半部分进行合...原创 2019-05-09 10:16:43 · 98 阅读 · 0 评论 -
insertion-sort-list
【题目描述】Sort a linked list using insertion sort.对链表使用插入排序【解题思路】新建一个头节点,遍历原来的链表,对原链表的每个节点找到新链表中适合插入位置的前指针,然后执行插入操作。这种操作链表的题有一个技巧就是新建一个newhead作为head,然后把数据插入到newhead的链表中,最后返回newhead->next。【考查内容】链表的插入排...原创 2019-05-09 10:45:46 · 93 阅读 · 0 评论 -
binary-tree-postorder-traversal
【题目描述】Given a binary tree, return the postorder traversal of its nodes’ values.For example:Given binary tree {1,#,2,3}12/3return [3,2,1].Note: Recursive solution is trivial, could you do it it...原创 2019-05-09 11:04:35 · 82 阅读 · 0 评论 -
copy-list-with-random-pointer
【题目描述】A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.【解题思路】最傻瓜的方法是首先遍历一次建立next关系的新l...原创 2019-05-14 20:18:31 · 84 阅读 · 0 评论 -
single-number
【题目描述】single-number-i:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement i...原创 2019-05-14 20:29:01 · 131 阅读 · 0 评论 -
word-ladder-ii
【题目描述】Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must...原创 2019-05-20 10:55:31 · 241 阅读 · 0 评论 -
valid-palindrome
【题目描述】Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"is not a p...原创 2019-05-20 11:02:21 · 558 阅读 · 0 评论 -
binary-tree-maximum-path-sum
【题目描述】Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree,1/ 2 3Return6.在二叉树中找一条路径,使得该路径的和最大。该路径可以从二叉树任何...原创 2019-05-20 11:17:59 · 120 阅读 · 0 评论 -
candy
【题目描述】There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on...原创 2019-05-15 11:49:20 · 145 阅读 · 0 评论 -
gas-station
【题目描述】There are N gas stations along a circular route, where the amount of gas at station i isgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from station i to it...原创 2019-05-15 13:05:56 · 730 阅读 · 0 评论 -
clone-graph
【题目描述】Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ’s undirected graph serialization:Nodes are labeled uniquely.We use#as a separator for each node,...原创 2019-05-15 13:27:38 · 173 阅读 · 0 评论 -
binary-tree-preorder-traversal
【题目描述】Given a binary tree, return the preorder traversal of its nodes’ values.For example:Given binary tree{1,#,2,3},12/3return[1,2,3].Note: Recursive solution is trivial, could you do it itera...原创 2019-05-10 20:32:33 · 95 阅读 · 0 评论 -
reorder-list
【题目描述】Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes’ values.For example,Given{1,2,3,4}, reorder...原创 2019-05-10 20:55:27 · 63 阅读 · 0 评论 -
linked-list-cycle-ii
【题目描述】Given a linked list, return the node where the cycle begins. If there is no cycle, return null.【解题思路】HashSet不能添加重复的元素,当调用add(Object)方法时,首先会调用Object的hashCode方法判hashCode是否已经存在,如不存在则直接插入元素;如果已存在则调...原创 2019-05-10 21:42:30 · 59 阅读 · 0 评论 -
path-sum
(i)【题目描述】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.For example:Given the below binary tree ...原创 2019-05-24 11:55:43 · 121 阅读 · 0 评论 -
balanced-binary-tree
【题目描述】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 depth of the two subtrees of every node never di...原创 2019-05-24 12:02:00 · 149 阅读 · 0 评论 -
best-time-to-buy-and-sell-stock
(i)【题目描述】Say you have an array for which the i th element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the...原创 2019-05-21 11:48:06 · 96 阅读 · 0 评论 -
palindrome-partitioning
【题目描述】Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s =“aab”,Return[[“aa”,“b”],[“a”...原创 2019-05-16 21:53:18 · 133 阅读 · 0 评论 -
palindrome-partitioning-ii
【题目描述】Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s =“aab”,Return1s...原创 2019-05-16 22:07:13 · 323 阅读 · 0 评论 -
surrounded-regions
【题目描述】Given a 2D board containing’X’and’O’, capture all regions surrounded by’X’.A region is captured by flipping all’O’s into’X’s in that surrounded region .For example,X X X XX O O XX X O XX O...原创 2019-05-16 22:15:27 · 111 阅读 · 0 评论 -
triangle
【题目描述】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],[4,1...原创 2019-05-22 10:45:50 · 186 阅读 · 0 评论 -
pascals-triangle
(i)【题目描述】Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5,Return[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]【解题思路】简单的按照杨辉三角形的规则计算就行了【考查内容】模拟class...原创 2019-05-22 11:13:40 · 262 阅读 · 0 评论 -
linked-list-cycle
【题目描述】Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断链表是否有环【解题思路】快慢指针:使用两个指针slow,fast。两个指针都从表头开始走,slow每次走一步,fast每次走两步,如果fast遇到null,则说...原创 2019-05-13 10:14:12 · 68 阅读 · 0 评论 -
sum-root-to-leaf-numbers
【题目描述】Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total...原创 2019-05-17 10:47:05 · 133 阅读 · 0 评论 -
longest-consecutive-sequence
【题目描述】Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3,...原创 2019-05-17 10:56:30 · 124 阅读 · 0 评论 -
word-ladder
【题目描述】Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate wo...原创 2019-05-17 11:10:47 · 160 阅读 · 0 评论 -
word-break
【题目描述】Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens =“leetcode”,dict =[“leet”,...原创 2019-05-13 10:42:32 · 645 阅读 · 0 评论 -
word-break-ii
【题目描述】Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = “c...原创 2019-05-13 10:58:31 · 60 阅读 · 0 评论 -
convert-sorted-list-to-binary-search-tree
【题目描述】Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.将一个顺序链表转换成一棵二叉树【解题思路】利用快慢指针,快指针比满指针每次多走一步slow = slow->next;fast = fast->nex...原创 2019-05-27 11:26:32 · 87 阅读 · 0 评论 -
converted-sorted-array-to-binary-search-tree
【题目描述】Given an array where elements are sorted in ascending order, convert it to a height balanced BST.【解题思路】将二叉查找树进行中序遍历,就可以得到一个升序排序的数组,因此,一个已经排序的数组可以看做一个中序遍历得到的数组,要得到一个高度平衡的二叉查找树,可以使得左右子树的节点数尽可能相等。...原创 2019-05-27 11:34:17 · 83 阅读 · 0 评论 -
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.【解题思路】递归方法:每个二叉树的最大深度=左子树的最大深度和右子树...原创 2019-05-27 11:59:45 · 158 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node
(i)【题目描述】Given a binary treestruct TreeLinkNode {TreeLinkNode *left;TreeLinkNode *right;TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right...原创 2019-05-23 10:21:39 · 156 阅读 · 0 评论 -
distinct-subsequences
【题目描述】Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be ...原创 2019-05-23 10:35:17 · 137 阅读 · 0 评论 -
same-tree
【题目描述】Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.给出两个2叉树,判断是...原创 2019-05-30 11:50:22 · 99 阅读 · 0 评论 -
recover-binary-search-tree
【题目描述】Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n ) space is pretty straight forward. Could you devis...原创 2019-05-30 12:10:55 · 94 阅读 · 0 评论 -
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.T...原创 2019-05-30 12:48:05 · 99 阅读 · 0 评论 -
binary-tree-level-order-traversal
(i)【题目描述】Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7},3/ 9 20/ 15 7r...原创 2019-05-28 09:58:21 · 255 阅读 · 0 评论