原文链接: https://leetcode-cn.com/problems/maximum-number-of-ways-to-partition-an-array 英文原文You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions: 1 <= p…
分类详情
困难 分类
原文链接: https://leetcode-cn.com/problems/longest-subsequence-repeated-k-times 英文原文You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s. A subsequence is a string that can be…
原文链接: https://leetcode-cn.com/problems/kth-smallest-product-of-two-sorted-arrays 英文原文Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the kth (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nu…
原文链接: https://leetcode-cn.com/problems/smallest-k-length-subsequence-with-occurrences-of-a-letter 英文原文You are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length…
原文链接: https://leetcode-cn.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference 英文原文You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of…
原文链接: https://leetcode-cn.com/problems/number-of-valid-move-combinations-on-chessboard 英文原文There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the ty…
原文链接: https://leetcode-cn.com/problems/second-minimum-time-to-reach-destination 英文原文A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented…
原文链接: https://leetcode-cn.com/problems/parallel-courses-iii 英文原文You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] …
原文链接: https://leetcode-cn.com/problems/check-if-an-original-string-exists-given-two-encoded-strings 英文原文An original string, consisting of lowercase English letters, can be encoded by the following steps: Arbitrarily split it into a sequence of some n…
原文链接: https://leetcode-cn.com/problems/maximum-path-quality-of-a-graph 英文原文There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. Yo…
原文链接: https://leetcode-cn.com/problems/count-fertile-pyramids-in-a-land 英文原文A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented…
原文链接: https://leetcode-cn.com/problems/process-restricted-friend-requests 英文原文You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1. You are also given a 0-indexed 2D integer array restriction…
原文链接: https://leetcode-cn.com/problems/sum-of-k-mirror-numbers 英文原文A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k. For example, 9 is a 2-mirror number. The r…
原文链接: https://leetcode-cn.com/problems/find-all-people-with-secret 英文原文You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] ind…
原文链接: https://leetcode-cn.com/problems/broken-board-dominoes 中文题目你有一块棋盘,棋盘上有一些格子已经坏掉了。你还有无穷块大小为1 * 2的多米诺骨牌,你想把这些骨牌不重叠地覆盖在完好的格子上,请找出你最多能在棋盘上放多少块骨牌?这些骨牌可以横着或者竖着放。 输入:n, m代表棋盘的大小;broken是一个b * 2的二维数组,其中每个元素代表棋盘上每一个坏掉的格子的位置。 输出:一个整数,代表最多能在棋盘上放的骨牌数。 示例 1: …
原文链接: https://leetcode-cn.com/problems/coin-bonus 中文题目力扣决定给一个刷题团队发LeetCoin作为奖励。同时,为了监控给大家发了多少LeetCoin,力扣有时候也会进行查询。 该刷题团队的管理模式可以用一棵树表示: 团队只有一个负责人,编号为1。除了该负责人外,每个人有且仅有一个领导(负责人没有领导); 不存在循环管理的情况,如A管理B,B管理C,C管理A。 力扣想进行的操作有以下三种: 给团队的一个成员(也可以是负责人)发一定数量的Leet…
原文链接: https://leetcode-cn.com/problems/pile-box-lcci 英文原文You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger tha…
原文链接: https://leetcode-cn.com/problems/eight-queens-lcci 英文原文Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals…
原文链接: https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof 中文题目请实现一个函数用来匹配包含'. '和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但与"aa.a"和"ab*a"均不匹配。 示例 1: 输入: s = "aa" p = "a"…
原文链接: https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof 中文题目请实现两个函数,分别用来序列化和反序列化二叉树。 你需要设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。 提示:输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这…
原文链接: https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof 中文题目输入一个整数 n ,求1~n这n个整数的十进制表示中1出现的次数。 例如,输入12,1~12这些整数中包含1 的数字有1、10、11和12,1一共出现了5次。 示例 1: 输入:n = 12 输出:5 示例 2: 输入:n = 13 输出:6 限制: 1
原文链接: https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof 中文题目在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 示例 1: 输入: [7,5,6,4] 输出: 5 限制: 0 <= 数组长度 <= 50000 通过代码 高赞题解📺 视频题解 📖 文字题解方法一:归并排序预备知识 「归并排序」是分治思想的典型应用,它包含这样三个步骤:…
原文链接: https://leetcode-cn.com/problems/bst-sequences-lcci 英文原文A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays …
原文链接: https://leetcode-cn.com/problems/continuous-median-lcci 英文原文Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. Median is the middle value in an ordered integ…
原文链接: https://leetcode-cn.com/problems/number-of-2s-in-range-lcci 英文原文Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive). Example: Input: 25 Output: 9 Explanation: (2, 12, 20, 21, 22, 23, 24, 25)(Note …
原文链接: https://leetcode-cn.com/problems/missing-two-lcci 英文原文You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space? You ca…
原文链接: https://leetcode-cn.com/problems/max-submatrix-lcci 英文原文Given an NxM matrix of positive and negative integers, write code to find the submatrix with the largest possible sum. Return an array [r1, c1, r2, c2], where r1, c1 are the row number and…
原文链接: https://leetcode-cn.com/problems/word-rectangle-lcci 英文原文Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms …
原文链接: https://leetcode-cn.com/problems/qie-fen-shu-zu 英文原文 中文题目给定一个整数数组 nums ,小李想将 nums 切割成若干个非空子数组,使得每个子数组最左边的数和最右边的数的最大公约数大于 1 。为了减少他的工作量,请求出最少可以切成多少个子数组。 示例 1: 输入:nums = [2,3,3,2,3,3] 输出:2 解释:最优切割为 [2,3,3,2] 和 [3,3] 。第一个子数组头尾数字的最大公约数为 2 ,第二个子数组头尾数…
原文链接: https://leetcode-cn.com/problems/er-cha-shu-ren-wu-diao-du 英文原文 中文题目任务调度优化是计算机性能优化的关键任务之一。在任务众多时,不同的调度策略可能会得到不同的总体执行时间,因此寻求一个最优的调度方案是非常有必要的。 通常任务之间是存在依赖关系的,即对于某个任务,你需要先完成他的前导任务(如果非空),才能开始执行该任务。我们保证任务的依赖关系是一棵二叉树,其中 root 为根任务,root.left 和 root.rig…