Leetcode Hard
文章平均质量分 73
_TCgogogo_
这个作者很懒,什么都没留下…
展开
-
LeetCode 992 Subarrays with K Different Integers (滑动窗 推荐)
题目分析:恰好有k个不好求,但至多有k个则非常容易,恰好k个=至多k个-至多k-1个,至多有k个可以用滑动窗,用hash判断每个数字出现的次数,并用一个值记录当前有多少个不同的数字。题目大意:求恰好有k个不同数字的区间个数。13ms,时间击败88.84%原创 2022-09-07 08:39:54 · 297 阅读 · 0 评论 -
LeetCode 1383 Maximum Performance of a Team (优先队列 贪心 推荐)
You are given two integersnandkand two integer arraysspeedandefficiencyboth of lengthn. There arenengineers numbered from1ton.speed[i]andefficiency[i]represent the speed and efficiency of theithengineer respectively.Chooseat mostkd...原创 2022-05-08 20:22:54 · 355 阅读 · 0 评论 -
LeetCode 23 Merge k Sorted Lists (分治)
You are given an array ofklinked-listslists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: [1,1,2,3,4,4,5,6]Explanati...原创 2022-01-26 21:24:35 · 208 阅读 · 0 评论 -
LeetCode 768. Max Chunks To Make Sorted II (思维)
You are given an integer arrayarr.We splitarrinto some number ofchunks(i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.Returnthe largest number of chunks we can make to sort ...原创 2022-01-24 21:17:11 · 103 阅读 · 0 评论 -
LeetCode 1032 Stream of Characters (Trie 推荐)
Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of stringswords.For example, ifwords = ["abc", "xyz"]and the stream added the four characters (one by one)'a','x','y', a...原创 2021-08-13 13:17:05 · 166 阅读 · 0 评论 -
LeetCode 1671 Minimum Number of Removals to Make Mountain Array (LIS 二分)
You may recall that an arrayarris amountain arrayif and only if:arr.length >= 3 There exists some indexi(0-indexed) with0 < i < arr.length - 1such that: arr[0] < arr[1] < ... < arr[i - 1] < arr[i] arr[i] > arr[i + 1] &...原创 2021-08-09 17:22:21 · 115 阅读 · 0 评论 -
LeetCode 1284 Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (bfs)
Given am x nbinary matrixmat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing1to0and0to1). A pair of cells are called neighbors if they share one edge.Return theminimum number o...原创 2021-07-30 14:09:00 · 171 阅读 · 0 评论 -
LeetCode 1425 Constrained Subsequence Sum (dp,滑动窗,推荐)
Given an integer arraynumsand an integerk, return the maximum sum of anon-emptysubsequence of that array such that for every twoconsecutiveintegers in the subsequence,nums[i]andnums[j], wherei < j, the conditionj - i <= kis satisfied.A...原创 2021-07-29 13:46:12 · 189 阅读 · 0 评论 -
LeetCode 1106 Parsing A Boolean Expression (分治,模拟)
Return the result of evaluating a given booleanexpression, represented as a string.An expression can either be:"t", evaluating toTrue; "f", evaluating toFalse; "!(expr)", evaluating to the logical NOT of the inner expressionexpr; "&(expr1,ex...原创 2021-07-27 13:58:01 · 139 阅读 · 0 评论 -
LeetCode 1312 Minimum Insertion Steps to Make a String Palindrome (dp)
Given a strings. In one step you can insert any character at any index of the string.Returnthe minimum number of stepsto makespalindrome.APalindrome Stringis one that reads the same backward as well as forward.Example 1:Input: s = "zzazz"...原创 2021-07-19 14:11:35 · 194 阅读 · 0 评论 -
LeetCode 1224 Maximum Equal Frequency (hash)
Given an arraynumsof positive integers, return the longest possible length of an array prefix ofnums, such that it is possible to removeexactly oneelement from this prefix so that every number that has appeared in it will have the same number of occur...原创 2021-07-19 14:00:48 · 156 阅读 · 0 评论 -
LeetCode 1373 Maximum Sum BST in Binary Tree (DFS, DP 推荐)
Given abinary treeroot, the task is to return the maximum sum of all keys ofanysub-tree which is also a Binary Search Tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key. ...原创 2021-07-15 23:43:36 · 187 阅读 · 3 评论 -
LeetCode 1547 Minimum Cost to Cut a Stick (推荐 区间dp)
Given a wooden stick of lengthnunits. The stick is labelled from0ton. For example, a stick of length6is labelled as follows:Given an integer arraycutswherecuts[i]denotes a position you should perform a cut at.You should perform the cuts in...原创 2021-07-04 20:09:30 · 338 阅读 · 1 评论 -
LeetCode 805 Split Array With Same Average (推荐 预处理 类01背包dp 详解 640ms -> 16ms)
You are given an integer arraynums.You should move each element ofnumsinto one of the two arraysAandBsuch thatAandBare non-empty, andaverage(A) == average(B).Returntrueif it is possible to achieve that andfalseotherwise.Notethat for ...原创 2021-07-04 18:45:00 · 265 阅读 · 2 评论 -
LeetCode 1235 Maximum Profit in Job Scheduling (dp 排序 二分)
We havenjobs, where every jobis scheduled to be done fromstartTime[i]toendTime[i], obtaining a profitofprofit[i].You're given thestartTime,endTimeandprofitarrays,you need to output the maximum profit you can take such that there are no 2 j...原创 2020-10-11 14:45:15 · 278 阅读 · 0 评论 -
LeetCode 135 Candy (贪心 构造)
LeetCode 135 Candy (贪心 构造)原创 2016-10-18 23:50:31 · 890 阅读 · 0 评论 -
LeetCode 85 Maximal Rectangle (最大子矩形 单调栈)
LeetCode 85 Maximal Rectangle (最大子矩形 单调栈)原创 2016-10-06 15:47:16 · 2375 阅读 · 0 评论 -
LeetCode 301 Remove Invalid Parentheses (BFS + 剪枝)
LeetCode 301 Remove Invalid Parentheses (BFS + 剪枝)原创 2016-10-08 09:39:00 · 1235 阅读 · 0 评论 -
LeetCode 212 Word Search II (Trie树+DFS)
LeetCode 212 Word Search II (Trie树+DFS)原创 2017-01-25 15:04:38 · 617 阅读 · 0 评论 -
LeetCode 41 First Missing Positive (思维)
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant spa原创 2018-01-15 14:18:10 · 259 阅读 · 0 评论 -
LeetCode 146 LRU Cache (双向链表 map)
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if th...原创 2019-02-14 23:30:33 · 345 阅读 · 0 评论 -
LeetCode 862 Shortest Subarray with Sum at Least K (单调队列 推荐)
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.If there is no non-empty subarray with sum at least K, return -1.Example 1:Input: A = [1], K = 1Outpu...原创 2019-02-12 14:40:52 · 1250 阅读 · 0 评论 -
LeetCode 10 Regular Expression Matching (正则匹配 记忆化搜索 推荐)
Given an input string (s) and a pattern (p), implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element....原创 2019-04-01 00:24:16 · 243 阅读 · 0 评论 -
LeetCode 44 Wildcard Matching (通配符匹配 记忆化搜索 剪枝 推荐)
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the...原创 2019-04-01 14:03:46 · 286 阅读 · 0 评论 -
LeetCode 552 Student Attendance Record II (dp)
Given a positive integern, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109+ 7.A stud...原创 2019-04-27 22:47:44 · 248 阅读 · 0 评论 -
LeetCode 778 Swim in Rising Water (二分 + DFS)
On an N x Ngrid, each squaregrid[i][j]represents the elevation at that point(i,j).Now rain starts to fall. At timet, the depth of the water everywhere ist. You can swim from a square to another...原创 2019-05-14 22:56:18 · 252 阅读 · 0 评论 -
LeetCode 685 Redundant Connection II (并查集 判树)
In this problem, a rooted tree is adirectedgraph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, excep...原创 2019-05-14 23:51:28 · 365 阅读 · 0 评论 -
LeetCode 1028 Recover a Tree From Preorder Traversal (栈 或 DFS 推荐)
We run apreorderdepth first search on therootof a binary tree.At each node in this traversal, we outputDdashes (whereDis thedepthof this node), then we output the value of this node.(If ...原创 2019-09-19 21:38:16 · 245 阅读 · 0 评论 -
LeetCode 57 Insert Interval (二分 + 模拟 推荐)
Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp...原创 2019-09-22 01:00:37 · 220 阅读 · 0 评论 -
LeetCode 72 Edit Distance (动态规划 一维空间优化)
LeetCode 72 Edit Distance (动态规划)原创 2016-09-01 13:45:32 · 939 阅读 · 0 评论 -
LeetCode 403 Frog Jump (dp)
LeetCode 403 Frog Jump (dp)原创 2016-10-16 13:29:42 · 1337 阅读 · 0 评论 -
LeetCode 188 Best Time to Buy and Sell Stock IV (动态规划 推荐)
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mostk transactions.Note:You may not engage in ...原创 2016-10-25 20:41:26 · 795 阅读 · 0 评论 -
LeetCode 123 Best Time to Buy and Sell Stock III (贪心)
LeetCode 123 Best Time to Buy and Sell Stock III (贪心)原创 2016-09-04 13:14:32 · 899 阅读 · 0 评论 -
LeetCode 37 Sudoku Solver
LeetCode 37 Sudoku Solver原创 2016-08-25 09:01:35 · 781 阅读 · 0 评论 -
LeetCode 354 Russian Doll Envelopes (LIS变形 推荐)
LeetCode 354 Russian Doll Envelopes (LIS变形 推荐)原创 2016-09-03 17:07:37 · 786 阅读 · 0 评论 -
LeetCode 52 N-Queens II (DFS)
LeetCode 52 N-Queens II (DFS)原创 2016-09-03 14:34:14 · 587 阅读 · 0 评论 -
LeetCode 273 Integer to English Words
LeetCode 273 Integer to English Words原创 2016-08-24 10:11:45 · 788 阅读 · 0 评论 -
LeetCode 316 Remove Duplicate Letters (队列+贪心)
LeetCode 316 Remove Duplicate Letters (队列+贪心)原创 2016-08-23 13:52:49 · 1277 阅读 · 2 评论 -
LeetCode 68 Text Justification (字符串格式处理)
LeetCode 68 Text Justification (字符串格式处理)原创 2016-08-23 13:10:33 · 609 阅读 · 0 评论 -
LeetCode 145 Binary Tree Postorder Traversal (后序遍历二叉树)
LeetCode 145 Binary Tree Postorder Traversal (后序遍历二叉树)原创 2016-08-31 10:02:51 · 951 阅读 · 0 评论