作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/largest-time-for-given-digits/description/ 题目描述 Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest…
题目如下: Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour time is 00:00, and the largest is 23:59.  Starting from 00:00, a time is larger if more time has elapsed since midnight. Return the answer as a s…
problem 949. Largest Time for Given Digits solution: class Solution { public: string largestTimeFromDigits(vector<int>& A) { sort(A.begin(), A.end(), greater<int>());//errr..largest.. do { ]< || (A[]==&&A[]<)) && A[]&…
[LeetCode]764. Largest Plus Sign 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-plus-sign/description/ 题目描述: In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except thos…
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-sum-of-averages/description/ 题目描述: We partition a row of numbers A into at most…
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a string instead of an i…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode.com/problems/largest-perimeter-triangle/ 题目描述 Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, f…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetcode.com/problems/largest-component-size-by-common-factor/description/ 题目描述 Given a non-empty array of unique positive integers A, consider the followin…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-divisible-subset/description/ 题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in thi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址: https://leetcode.com/problems/largest-rectangle-in-histogram/description/ 题目描述 Given n non-negative integers representing the histogram's bar height where the widt…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 寻找两次最大值 排序 大顶堆 日期 题目地址:https://leetcode.com/problems/largest-number-at-least-twice-of-others/description/ 题目描述 In a given integer array nums, there is always exactly one larges…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/largest-palindrome-product/description/ 题目描述 Find the largest palindrome made from the product of two n-digit numbers. Since the result co…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 三重循环 组合函数 日期 题目地址:https://leetcode.com/problems/largest-triangle-area/description/ 题目描述 You have a list of points in the plane. Return the area of the largest triangle that can…
Find 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. For example,Given [3,2,1,5,6,4] and k = 2, return 5. 思路: 堆.讲解:二叉堆 class Solution { public: //新插入i结点 其父节点为(i…
Largest Rectangle in Histogram Given 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 heigh…
题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0. If there are multiple solutions, return any subset is fine. 解题分析: 如果a%b==0,则a=mb,…
题目: Given 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 = [2,1,5,6,2,3]. The larg…
Given 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 =[2,1,5,6,2,3]. The largest r…
问题描述: 84:直方图最大面积. 85:0,1矩阵最大全1子矩阵面积. 问题分析: 对于84,如果高度递增的话,那么OK没有问题,不断添加到栈里,最后一起算面积(当然,面积等于高度h * disPos,这里的高度取决于两个h的较小者,那么如果有序的话,只需要计算每一个最小值h,在用到当前位置与最小值h所在位置的差值,也就是柱子数目,就OK了).如果新h[i]的高度比之前的高度小的话,那么就可以认为之前所有比h[i]高的柱子都需要计算一下面积,然后对于破坏递增规则的h[i]会继续加入栈中.为甚会…
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9] 题目要求计算二叉树每一层的最大值,并且将最大值组成一个列表输出.从题目要求很容易可以看出,这是一个二叉树的层序遍历,在遍历的过程中对比求出每一层的最大值.层序遍历的思路就是从根节点开始,依次把每个节点的左右节点放入一个队列中,接着依次遍历队列中的所有节点.…
题目如下: We 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_wanted For every label L, the number of items in Swith label L is <= use_limit. Return the largest…
题目如下: Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it is impossible to form any triangle of non-zero area, return 0. Example 1: Input: [2,1,2] Output: 5 Exampl…
You are given an integer array of unique positive integers nums. Consider the following graph: There are nums.length nodes, labeled nums[0] to nums[nums.length - 1], There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcode-cn.com/problems/largest-bst-subtree/ 题目描述 Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means sub…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 桶排序 日期 题目地址:https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/ 题目描述 Given an array of integers A`, return the largest integer that only oc…
题目如下: 解题思路:求最值的题目优先考虑是否可以用动态规划.记dp[i][j]表示在数组A的第j个元素后面加上第i+1 (i从0开始计数)个分隔符后可以得到的最大平均值,那么可以得到递归关系式: dp[i][j] = max(dp[i][j],dp[i-1][k]+float(sum(A[k+1:j+1]))/float(j-k)) . 代码如下: class Solution(object): def largestSumOfAverages(self, A, K): ""&quo…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/count-numbers-with-unique-digits/description/ 题目描述 Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x <…
题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. 解题分析: 题目要就就是找出 0≤ x < 10n中各位数字都不相同的数的个数.要接触这道题只需要理解: 1.设f(n)表示n为数字中各位都不相同的个数,则有countNumbersWithUniqueDigits(n)=f(1)+f(2)+……+f(n)=f(n)+countNumbersWithU…
题目如下: We are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc. Each node may have a next larger value: for node_i, next_larger(node_i) is the node_j.val such that j > i, node_j.val…
题目如下: 解题思路:我的想法对于数组中任意一个元素,找出其左右两边最近的小于自己的元素.例如[1,3,2,4,5,1],元素2左边比自己小的元素是1,那么大于自己的区间就是[3],右边的区间就是[4,5].那么对于元素2来说,和左边区间合并组成[2,3]以及和右边区间合并组成[2,4,5],这两段区间包括2在内的所有subarray的最小值都是2,其分别可以组成的subarry的个数是 len([3])和len([4,5]),左右区间合并在一起可以组成的subarray的个数是len([3])…