LeetCode 解题报告
caicaiatnbu
这个作者很懒,什么都没留下…
展开
-
[LeetCode 解题报告]155. Min Stack
Design 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() -- Ge...原创 2020-02-01 17:00:24 · 180 阅读 · 0 评论 -
[LeetCode 解题报告]154. Find Minimum in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7]might become [4,5,6,7,0,1,2]).Find the minimum element.The array may contai...原创 2020-02-01 16:53:29 · 157 阅读 · 0 评论 -
[LeetCode 解题报告]153. Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7]might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume no du...原创 2020-02-01 16:28:34 · 150 阅读 · 0 评论 -
[LeetCode 解题报告]152. Maximum Product Subarray
Given an integer arraynums, 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] ...原创 2020-02-01 16:09:35 · 134 阅读 · 0 评论 -
[LeetCode 解题报告]151. Reverse Words in a String
Given an input string, reverse the string word by word.Example 1:Input: "the sky is blue"Output:"blue is sky the"Example 2:Input: " hello world! "Output:"world! hello"Explanation: ...原创 2020-02-01 14:28:56 · 150 阅读 · 0 评论 -
[LeetCode 解题报告]150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Note:Division between two integers ...原创 2020-01-30 22:59:11 · 197 阅读 · 0 评论 -
[LeetCode 解题报告]149. Max Points on a Line
Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Output: 3Explanation:^|| o| o| o +-----...原创 2020-01-30 22:48:14 · 205 阅读 · 0 评论 -
[LeetCode 解题报告]148. Sort List
Sort a linked list inO(nlogn) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1-...原创 2020-01-30 15:00:38 · 143 阅读 · 0 评论 -
[LeetCode 解题报告]147. Insertion Sort List
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element...原创 2020-01-30 14:40:22 · 192 阅读 · 0 评论 -
[LeetCode 解题报告]146. LRU Cache
Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...原创 2020-01-30 14:37:51 · 155 阅读 · 0 评论 -
[LeetCode 解题报告]145. Binary Tree Postorder Traversal
Given a binary tree, return thepostordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[3,2,1]Follow up:Recursive solution is trivial, coul...原创 2020-01-27 17:30:04 · 164 阅读 · 0 评论 -
[LeetCode 解题报告]144. Binary Tree Preorder Traversal
Given a binary tree, return thepreordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[1,2,3]Follow up:Recursive solution is trivial, could...原创 2020-01-21 15:11:37 · 140 阅读 · 0 评论 -
[LeetCode 解题报告]056. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...原创 2019-11-10 21:41:33 · 91 阅读 · 0 评论 -
[LeetCode 解题报告]143. Reorder List
Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You maynotmodify the values in the list's nodes, only nodes itself may be changed.Example 1:Given 1->2-...原创 2020-01-05 22:44:46 · 157 阅读 · 0 评论 -
[LeetCode 解题报告]142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-i...原创 2020-01-04 23:47:24 · 143 阅读 · 0 评论 -
[LeetCode 解题报告]141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where tail co...原创 2020-01-04 23:41:50 · 110 阅读 · 0 评论 -
[LeetCode 解题报告]140. Word Break II
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible ...原创 2020-01-04 23:37:08 · 148 阅读 · 0 评论 -
[LeetCode 解题报告]139. Word Break
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.Note:The ...原创 2020-01-04 23:22:15 · 121 阅读 · 0 评论 -
[LeetCode 解题报告]138. 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 adeep copyof the list.The Linked List is represented in ...原创 2020-01-04 23:19:48 · 286 阅读 · 0 评论 -
[LeetCode 解题报告]137. Single Number II
Given anon-emptyarray of integers, every element appearsthreetimes except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity....原创 2020-01-04 21:40:58 · 119 阅读 · 0 评论 -
[LeetCode 解题报告]136. Single Number
Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...原创 2020-01-03 17:12:27 · 125 阅读 · 0 评论 -
[LeetCode 解题报告]135. Candy
There areNchildren 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 one ca...原创 2020-01-03 17:07:16 · 138 阅读 · 0 评论 -
[LeetCode 解题报告]134. Gas Station
There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its ...原创 2020-01-03 17:00:14 · 121 阅读 · 0 评论 -
[LeetCode 解题报告]133. Clone Graph
Givena reference of a node in aconnectedundirected graph, return adeep copy(clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Example:...原创 2020-01-03 11:44:19 · 193 阅读 · 0 评论 -
[LeetCode 解题报告]132. Palindrome Partitioning II
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.Example:Input:"aab"Output: 1Explana...原创 2020-01-03 11:27:02 · 144 阅读 · 0 评论 -
[LeetCode 解题报告]131. Palindrome Partitioning
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.Example:Input:"aab"Output:[ ["aa","b"], ["a","a"...原创 2019-12-30 23:47:08 · 138 阅读 · 0 评论 -
[LeetCode 解题报告]130. Surrounded Regions
Given a 2D board containing'X'and'O'(the letter O), capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.Example:X X X XX O O...原创 2019-12-29 15:36:50 · 116 阅读 · 0 评论 -
[LeetCode 解题报告]125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.Examp...原创 2019-12-29 15:04:06 · 94 阅读 · 0 评论 -
[LeetCode 解题报告]129. 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 tota...原创 2019-12-28 16:52:18 · 116 阅读 · 0 评论 -
[LeetCode 解题报告]128. Longest Consecutive Sequence
Given 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: 4Ex...原创 2019-12-28 16:43:19 · 137 阅读 · 0 评论 -
[LeetCode 解题报告]127. Word Ladder
Given two words (beginWordandendWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only one letter can be changed at a ti...原创 2019-12-28 16:20:09 · 165 阅读 · 0 评论 -
[LeetCode 解题报告]124. Binary Tree Maximum Path Sum
Given anon-emptybinary 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 connectio...原创 2019-12-28 15:52:41 · 173 阅读 · 0 评论 -
[LeetCode 解题报告]123. Best Time to Buy and Sell Stock III
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not e...原创 2019-12-28 15:36:04 · 134 阅读 · 0 评论 -
[LeetCode 解题报告]122. Best Time to Buy and Sell Stock II
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy on...原创 2019-12-28 00:15:07 · 104 阅读 · 0 评论 -
[LeetCode 解题报告]121. Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2019-12-28 00:10:58 · 117 阅读 · 0 评论 -
[LeetCode 解题报告]120. 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...原创 2019-12-28 00:03:50 · 120 阅读 · 0 评论 -
[LeetCode 解题报告]119. Pascal's Triangle II
Given a non-negativeindexkwherek≤33, return thekthindex row of the Pascal's triangle.Note that the row index starts from0.In Pascal's triangle, each number is the sum of the two numbers ...原创 2019-12-27 23:54:19 · 89 阅读 · 0 评论 -
[LeetCode 解题报告]118. Pascal's Triangle
Given a non-negative integernumRows, generate the firstnumRowsof Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:...原创 2019-12-26 23:02:20 · 103 阅读 · 0 评论 -
[LeetCode 解题报告]117. Populating Next Right Pointers in Each Node II
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 point...原创 2019-12-25 23:40:12 · 175 阅读 · 0 评论 -
[LeetCode 解题报告]116. Populating Next Right Pointers in Each Node
You are given aperfect binary treewhereall 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; ...原创 2019-12-25 22:42:22 · 185 阅读 · 0 评论