- 博客(41)
- 资源 (6)
- 收藏
- 关注
原创 LeetCode解题报告:309. Best Time to Buy and Sell Stock with Cooldown
ProblemSay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, b...
2019-08-31 14:53:52 340
原创 LeetCode解题报告:714. Best Time to Buy and Sell Stock with Transaction Fee
ProblemYour are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete a...
2019-08-31 14:36:12 347
原创 LeetCode解题报告:121. Best Time to Buy and Sell Stock
ProblemSay you have an array for which the ithi^{th}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 shar...
2019-08-31 14:02:06 357
原创 LeetCode解题分享:1011. Capacity To Ship Packages Within D Days
ProblemA conveyor belt has packages that must be shipped from one port to another within D days.The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with pac...
2019-08-30 15:14:41 319
原创 LeetCode解题分享:82. Remove Duplicates from Sorted List II
ProblemGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output:...
2019-08-29 16:38:51 160
原创 LeetCode解题分享:430. Flatten a Multilevel Doubly Linked List
ProblemYou are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child ...
2019-08-29 16:15:44 333
原创 LeetCode解题分享:117. Populating Next Right Pointers in Each Node II
problemGiven 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...
2019-08-29 14:16:25 388
原创 LeetCode解题分享:684. Redundant Connection
ProblemIn this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one a...
2019-08-29 14:05:08 142
原创 LeetCode解题分享:863. All Nodes Distance K in Binary Tree
ProblemWe 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 b...
2019-08-28 23:40:09 341
原创 LeetCode解题分享:1013. Partition Array Into Three Parts With Equal Sum
ProblemGiven an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums.Formally, we can partition the array if we can find indexes i+1 ...
2019-08-27 15:02:55 207
原创 LeetCode解题分享:1029. Two City Scheduling
ProblemThere are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1].Return the...
2019-08-27 14:44:31 226
原创 LeetCode解题分享:372. Super Pow
ProblemYour task is to calculate aba^bab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example 1:Input: a = 2, b = [3]Output: 8...
2019-08-26 21:30:55 177
原创 LeetCode解题分享:475. Heaters
ProblemWinter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions of houses and heaters on a horizo...
2019-08-26 20:49:54 218
原创 LeetCode解题分享:1073. Adding Two Negabinary Numbers
ProblemGiven two numbers arr1 and arr2 in base -2, return the result of adding them together.Each number is given in array format: as an array of 0s and 1s, from most significant bit to least signi...
2019-08-26 15:33:38 582
原创 LeetCode解题分享:1093. Statistics from a Large Sample
ProblemWe sampled integers between 0 and 255, and stored the results in an array count: count[k] is the number of integers we sampled equal to k.Return the minimum, maximum, mean, median, and mode ...
2019-08-25 17:04:20 474
原创 LeetCode解题分享:1054. Distant Barcodes
ProblemIn a warehouse, there is a row of barcodes, where the i-th barcode is barcodes[i].Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guar...
2019-08-25 16:01:33 359
原创 LeetCode解题分享:238. Product of Array Except Self
ProblemGiven 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]Ou...
2019-08-25 15:18:41 137
原创 LeetCode解题分享:1104. Path In Zigzag Labelled Binary Tree
ProblemIn an infinite binary tree where every node has two children, the nodes are labelled in row order.In the odd numbered rows (ie., the first, third, fifth,…), the labelling is left to right, wh...
2019-08-24 14:01:41 622
原创 LeetCode解题分享:137. Single Number II
ProblemGiven a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime comp...
2019-08-23 14:51:47 148
原创 LeetCode解题分享:215. Kth Largest Element in an Array
ProblemFind 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:...
2019-08-23 13:31:23 357
原创 LeetCode解题分享:36. Valid Sudoku
ProblemDetermine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column mus...
2019-08-22 15:51:53 107
原创 LeetCode解题分享:16. 3Sum Closest
ProblemGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each inpu...
2019-08-22 15:29:20 134
原创 LeetCode解题分享:73. Set Matrix Zeroes
ProblemGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.Example 1:Input:[[1,1,1],[1,0,1],[1,1,1]]Output:[[1,0,1],[0,0,0],[1,0,1]]Example 2:...
2019-08-22 15:24:28 161
原创 LeetCode解题分享:78. Subsets
ProblemGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[...
2019-08-22 14:23:33 152
原创 LeetCode解题分享:547. Friend Circles
ProblemThere are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of ...
2019-08-20 21:06:01 142
原创 LeetCode解题分享:911. Online Election
ProblemIn an election, the i-th vote was cast for persons[i] at time times[i].Now, we would like to implement the following query function: TopVotedCandidate.q(int t) will return the number of the p...
2019-08-20 19:50:35 184
原创 LeetCode解题分享:692. Top K Frequent Words
ProblemGiven a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with...
2019-08-20 17:10:02 326
原创 LeetCode解题分享:17. Letter Combinations of a Phone Number
ProblemGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons)...
2019-08-20 13:26:39 166
原创 LeetCode解题分享:1162. As Far from Land as Possible
ProblemGiven an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized and return th...
2019-08-19 13:34:15 1255
原创 LeetCode解题分享:1161. Maximum Level Sum of a Binary Tree
ProblemGiven the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.Return the smallest level X such that the sum of all the values of nodes at level X is m...
2019-08-18 15:10:48 457
原创 LeetCode解题分享:743. Network Delay Time
ProblemThere are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it t...
2019-08-18 14:52:37 180
原创 LeetCode解题分享:210. Course Schedule II
ProblemThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as...
2019-08-17 16:16:22 439
原创 LeetCode解题分享:207. Course Schedule
ProblemThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as...
2019-08-17 16:02:11 157
原创 LeetCode解题分享:752. Open the Lock
ProblemYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we ...
2019-08-17 14:57:02 149
原创 LeetCode解题分享:394. Decode String
ProblemGiven an encoded string, return its decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k ...
2019-08-15 15:37:37 202
原创 LeetCode解题分享:1155. Number of Dice Rolls With Target Sum
ProblemYou have ddd dice, and each die has fff faces numbered 1, 2, …, f.Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the face up numbers ...
2019-08-15 14:08:50 1289
原创 LeetCode解题分享:1090. Largest Values From Labels
ProblemWe have a set of items: the i-th item has value values[i] and label labels[i].Then, we choose a subset S of these items, such that:|S| <= num_wantedFor every label L, the number of ite...
2019-08-14 15:48:21 351
原创 LeetCode解题分享:851. Loud and Rich
ProblemIn a group of N people (labelled 0, 1, 2, …, N-1), each person has different amounts of money, and different levels of quietness.For convenience, we’ll call the person with label x, simply “p...
2019-08-14 15:12:44 199
原创 LeetCode解题分享:1143. Longest Common Subsequence
ProblemGiven two strings text1 and text2, return the length of their longest common subsequence.A subsequence of a string is a new string generated from the original string with some characters(can ...
2019-08-14 13:36:53 2223
原创 LeetCode解题分享:1094. Car Pooling
ProblemYou are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.)Given a list of trips, tri...
2019-08-13 23:53:32 638
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人