![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 87
@YangZai
这个作者很懒,什么都没留下…
展开
-
【数据结构与算法】Leetcode407 接雨水 II -困难(堆、BFS)
接雨水II是对接雨水I的拓展,将一维数组扩展到了二维矩阵,之前接雨水I中的动态规划、单调栈以及双指针在这里都不起作用,但是在我之前介绍接雨水I的文章中对双指针进行了分析和延伸,延伸出的更通用的解法即优先队列解法则可以轻易地移植到接雨水II中。原创 2021-06-01 04:46:33 · 645 阅读 · 0 评论 -
【Leetcode周赛】第243场周赛 T3 - 1882. 使用服务器处理任务 - 中等(堆/优先队列)
来源:力扣题目描述给你两个下标从 0 开始 的整数数组 servers 和 tasks ,长度分别为 n 和 m 。servers[i] 是第 i 台服务器的权重 ,而 tasks[j] 是处理第 j 项任务所需要的时间(单位:秒)。 你正在运行一个仿真系统,在处理完所有任务后,该系统将会关闭。每台服务器只能同时处理一项任务。第 0 项任务在第 0 秒可以开始处理,相应地,第 j 项任务在第 j 秒可以开始处理。处理第 j 项任务时,你需要为它原创 2021-05-31 08:15:21 · 317 阅读 · 0 评论 -
【数据结构与算法】Leetcode42 接雨水I -困难(动态规划、单调栈、双指针、堆)
接雨水I算是Leetcode上比较经典而且有意思的题了,解法也有挺多的,有官方题解介绍的动态规划、单调栈、双指针,还有我补充的堆解法,这篇文章不是搬运文,而是对官方题解的补充,而且将接雨水II的解法移植到了接雨水I中,展示了更通用的这类题型的解法和思路。原创 2021-05-29 16:21:17 · 191 阅读 · 0 评论 -
【Leetcode每日一题】2021-05-04 740 删除并获得点数 - 中等 - 动态规划 (Python & C++)
来源:力扣给你一个整数数组 nums ,你可以对它进行一些操作。每次操作中,选择任意一个 nums[i] ,删除它并获得 nums[i] 的点数。之后,你必须删除每个等于 nums[i] - 1 或 nums[i] + 1 的元素。开始你拥有 0 个点数。返回你能通过这些操作获得的最大点数。示例 1:输入:nums = [3,4,2]输出:6解释:删除 4 获得 4 个点数,因此 3 也被删除。之后,删除 2 获得 2 个点数。总共获得 6 个点数。示例 2:输入:nums = [2原创 2021-05-05 03:39:25 · 178 阅读 · 0 评论 -
【Leetcode每日一题】2021-05-03 1473 粉刷房子III - 困难 - 动态规划 (Python & C++)
来源:力扣在一个小城市里,有 m 个房子排成一排,你需要给每个房子涂上 n 种颜色之一(颜色编号为 1 到 n )。有的房子去年夏天已经涂过颜色了,所以这些房子不需要被重新涂色。我们将连续相同颜色尽可能多的房子称为一个街区。(比方说 houses = [1,2,2,3,3,2,1,1] ,它包含 5 个街区 [{1}, {2,2}, {3,3}, {2}, {1,1}] 。)给你一个数组 houses ,一个 m * n 的矩阵 cost 和一个整数 target ,其中:houses[i]:是原创 2021-05-05 00:27:56 · 213 阅读 · 3 评论 -
【Leetcode每日一题】2020-09-11 637 二叉树的层平均值 - 简单 (Python & C++)
来源:力扣给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.示例 1:输入: 3 / \ 9 20 / \ 15 7输出:[3, 14.5, 11]解释:第 0 层的平均值是 3 , 第1层是 14.5 , 第2层是 11 。因此返回原创 2020-09-14 06:10:45 · 133 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-10 216 组合总和 III - 中等 (Python & C++)
来源:力扣找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。说明:所有数字都是正整数。解集不能包含重复的组合。Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set原创 2020-09-12 04:08:34 · 159 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-09 40 组合总和 II - 中等 (Python & C++)
来源:力扣给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的每个数字在每个组合中只能使用一次。说明:所有数字(包括目标数)都是正整数。解集不能包含重复的组合。Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations i原创 2020-09-10 04:08:48 · 125 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-08 39 组合总和 - 中等 (Python & C++)
来源:力扣给定一个无重复元素的数组 candidates 和一个目标数 target ,找出candidates 中所有可以使数字和为 target 的组合。candidates 中的数字可以无限制重复被选取。Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where th原创 2020-09-09 04:13:09 · 125 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-05 107 二叉树的层次遍历 II - 简单 (Python & C++)
来源:力扣给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \9原创 2020-09-06 06:10:41 · 71 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-03 257 二叉树的所有路径 - 简单 (Python & C++)
来源:力扣给定一个二叉树,返回所有从根节点到叶子节点的路径。说明: 叶子节点是指没有子节点的节点。示例:输入: 1 / \2 3 \ 5输出: [“1->2->5”, “1->3”]解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3思路:深度优先搜索 DFSPython# Definition for a binary tre原创 2020-09-06 06:08:38 · 108 阅读 · 0 评论 -
【Leetcode每日一题】2020-09-02 剑指Offer 20 表示数值的字符串 - 中等 Python
来源:力扣请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。示例:字符串"+100"、“5e2”、"-123"、“3.1416”、"-1E-16"、"0123"都表示数值;“12e”、“1a3.14”、“1.2.3”、"±5"及"12e+5.4"都不是。解题思路:作者:jyd来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/solution/mian-s原创 2020-09-06 06:06:26 · 127 阅读 · 0 评论 -
【Leetcode每日一题】2020-08-25 491 递增子序列 - 中等 (Python & C++)
来源:力扣给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是2。Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2.示例:输入: [4, 6, 7, 7]输出:原创 2020-09-06 06:02:20 · 151 阅读 · 0 评论 -
【Leetcode每日一题】2020-08-23 201 数字范围按位与 - 中等 (Python & C++)
来源:力扣给定范围 [m, n],其中 0 <= m <= n <= 2147483647,返回此范围内所有数字的按位与(包含 m, n 两端点)。Given a range [m, n] where 0 <= m <= n <= 2147483647, return thebitwise AND of all numbers in this range, inclusive.思路:2147483647的二进制为31位的1组成,最粗暴的做法是直接用它递归地原创 2020-09-06 05:58:43 · 111 阅读 · 0 评论