
Leetcode Favorate [图解]
哦我的上帝啊,让我看看哪个小傻瓜还不会这里的题?(Top 100 liked questions 和 Top interview questions 交集)
Super_Whw
这个作者很懒,什么都没留下…
展开
-
5. Longest Palindromic Substring(图解)
5. Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:Input: "cbbd"Outpu原创 2020-10-30 00:01:11 · 256 阅读 · 0 评论 -
46. Permutations(图解)
46. PermutationsGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]SolutionC++class Solution {public: vector<vector<原创 2020-10-19 23:38:41 · 177 阅读 · 0 评论 -
84. Largest Rectangle in Histogram(图解)
84. Largest Rectangle in HistogramGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height原创 2020-10-18 10:12:06 · 145 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree(图解)
297. Serialize and Deserialize Binary TreeSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructe原创 2020-10-18 10:11:38 · 261 阅读 · 0 评论 -
98. Validate Binary Search Tree(图解)
98. Validate Binary Search TreeGiven 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 right subtree of a node con原创 2020-10-18 10:11:10 · 343 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree(图解)
236. Lowest Common Ancestor of a Binary TreeGiven 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 and q as the原创 2020-10-15 00:24:07 · 173 阅读 · 0 评论 -
283. Move Zeroes(图解)
TitleProblemExample:contentSolutionC++cppPythonpython原创 2020-10-15 00:23:26 · 119 阅读 · 0 评论 -
22. Generate Parentheses(图解)
22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example 1:Input: n = 3Output: ["((()))","(()())","(())()","()(())","()()()"]Example 2:Input: n = 1Output: ["()"]Solutio原创 2020-10-15 00:23:01 · 157 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number(图解)
17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.A mapping of digit to letters (just like on the telephon原创 2020-10-15 00:22:38 · 124 阅读 · 0 评论 -
15. 3Sum(图解)
15. 3SumGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Notice that the solution set must not contain duplicate triplets.Example 1:Input: n原创 2020-10-13 23:50:56 · 312 阅读 · 0 评论 -
10. Regular Expression Matching(图解)
10. Regular Expression MatchingGiven an input string (s) and a pattern §, implement regular expression matching with support for ‘.’ and ‘*’ where:‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.The matching shou原创 2020-10-08 20:44:57 · 456 阅读 · 0 评论 -
206. Reverse Linked List(图解)
206. Reverse Linked ListReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLSolutionC++Sol1:/** * Definition for singly-linked list. * struct ListNode { * int val; * L原创 2020-10-07 22:19:06 · 431 阅读 · 0 评论 -
105. Construct Binary Tree from Preorder and Inorder Traversal(图解)
105. Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3,9,20,15,7]inorder = [原创 2020-10-07 11:47:20 · 286 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock(图解)
121. Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm原创 2020-10-07 11:44:23 · 210 阅读 · 0 评论 -
124. Binary Tree Maximum Path Sum(图解)
124. Binary Tree Maximum Path SumGiven 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 connections. The path must conta原创 2020-10-07 11:43:04 · 198 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree(图解)
104. Maximum Depth of Binary TreeGiven 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.Example:Given binary原创 2020-10-05 18:09:16 · 161 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal(图解)
102. Binary Tree Level Order TraversalGiven 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,null,null,15,7], 3 / \ 9 20 / \ 15 7re原创 2020-10-05 18:08:39 · 282 阅读 · 0 评论 -
101. Symmetric Tree(图解)
101. Symmetric TreeGiven 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 the following [1,2,2,null,3,null,3]原创 2020-10-05 18:07:28 · 226 阅读 · 0 评论 -
215. Kth Largest Element in an Array(图解)
215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Example 2:Input: [3,2,3原创 2020-10-04 10:21:31 · 126 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal(图解)
94. Binary Tree Inorder TraversalGiven the root of a binary tree, return the inorder traversal of its nodes’ values.Example:Input: root = [1,null,2,3]Output: [1,3,2]Example 2:Input: root = []Output: []Example 3:Input: root = [1]Output: [1]So原创 2020-10-04 10:14:05 · 176 阅读 · 0 评论 -
160. Intersection of Two Linked Lists(图解)
160. Intersection of Two Linked ListsWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:Input: intersectVal = 8, listA = [4原创 2020-10-03 20:16:42 · 160 阅读 · 0 评论 -
240. Search a 2D Matrix II(图解)
240. Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending原创 2020-10-02 11:30:12 · 81 阅读 · 0 评论 -
234. Palindrome Linked List(图解)
234. Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueSolutionC++/** * Definition for singly-linked list. * struct ListNode原创 2020-10-02 11:29:42 · 160 阅读 · 0 评论 -
148. Sort List(图解)
148. Sort ListGiven the head of a linked list, return the list after sorting it in ascending order.Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?Example 1:Input: head = [4,2,1,3]Output: [1,2,3,4]Exam原创 2020-10-02 11:29:16 · 199 阅读 · 0 评论 -
155. Min Stack(图解)
155. Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the top element.getMin() – Retrieve the mini原创 2020-10-02 11:28:37 · 88 阅读 · 0 评论 -
152. Maximum Product Subarray(图解)
152. Maximum Product SubarrayGiven an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has the largest product 6.Ex原创 2020-10-02 09:22:09 · 135 阅读 · 0 评论 -
141. Linked List Cycle(图解)
141. Linked List CycleGiven head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internal原创 2020-09-28 21:09:35 · 233 阅读 · 0 评论 -
169. Majority Element(图解)
169. Majority ElementGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always exist in the array.Example 1:I原创 2020-09-28 21:09:10 · 109 阅读 · 0 评论 -
146. LRU Cache(图解)
146. LRU CacheDesign a data structure that follows the constraints of a Least Recently Used (LRU) cache.Implement the LRUCache class:LRUCache(int capacity) Initialize the LRU cache with positive size capacity.int get(int key) Return the value of the k原创 2020-09-28 21:08:41 · 208 阅读 · 0 评论 -
198. House Robber(图解)
198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and i原创 2020-09-28 21:08:07 · 155 阅读 · 0 评论 -
139. Word Break(图解)
139. Word BreakGiven a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The same word in the dictionary may be reused原创 2020-09-27 21:43:50 · 291 阅读 · 0 评论 -
238. Product of Array Except Self(图解)
238. Product of Array Except SelfGiven an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Output: [24,12,8,6]Constraint:原创 2020-09-27 21:40:15 · 76 阅读 · 0 评论 -
279. Perfect Squares(图解)
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example 2:Input: n = 13Output: 2Explanation:原创 2020-09-23 00:13:52 · 134 阅读 · 0 评论 -
207. Course Schedule(图解)
207. Course ScheduleThere are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given the原创 2020-09-23 00:10:02 · 349 阅读 · 0 评论 -
200. Number of Islands(图解)
200. Number of IslandsGiven a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are a原创 2020-09-22 08:55:38 · 95 阅读 · 0 评论 -
79. Word Search(图解)
79. Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not原创 2020-09-22 08:55:02 · 1234 阅读 · 0 评论 -
128. Longest Consecutive Sequence(图解)
128. Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Explanation: The longest con原创 2020-09-22 08:54:37 · 125 阅读 · 0 评论 -
136. Single Number(图解)
136. Single NumberGiven a non-empty array of integers, every element appears twice except for one. Find that single one.Example 1:Input: [2,2,1]Output: 1Example 2:Input: [4,1,2,1,2]Output: 4SolutionC++class Solution {public: int singleNumb原创 2020-09-22 08:53:32 · 158 阅读 · 1 评论 -
76. Minimum Window Substring(图解)
76. Minimum Window SubstringGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"SolutionC++class Solution {public:原创 2020-09-22 08:53:07 · 135 阅读 · 0 评论 -
75. Sort Colors(图解)
75. Sort ColorsGiven an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color原创 2020-09-22 08:52:28 · 69 阅读 · 0 评论