LeetCode
文章平均质量分 84
计科小白菜的算法之旅
&再见萤火虫&
不卑不亢,沉稳可靠。
展开
-
LeetCode_BinaryTree_1129. Shortest Path with Alternating Colors 颜色交替的最短路径【BFS求最短路径】【java】【中等】
BFS求最短颜色交替路径原创 2022-09-20 11:28:46 · 268 阅读 · 0 评论 -
LeetCode_Array_1004. Max Consecutive Ones III 最大连续1的个数 III【滑动数组】【Java】【中等】
滑动窗口求最大连续为1的数组长度原创 2022-09-18 15:13:14 · 259 阅读 · 0 评论 -
LeetCode_Array_88. Merge Sorted Array 合并两个有序数组【从后向前遍历】【Java】【简单】
合并有序数组原创 2022-09-18 14:45:15 · 164 阅读 · 0 评论 -
LeetCode_Array_215. Kth Largest Element in an Array 数组中的第K个最大元素【优先队列,快速排序】【Java】【中等】
快速排序中有一个partition方法,通过选择哨兵元素,将数组以哨兵为基准划分为两部分,并将哨兵放在两部分中间,这个哨兵所在位置即最终位置,如果这个位置就是k-1(以0开始),游戏结束;很直白的思路是,通过优先队列创建小根堆,存储前K大元素,堆顶即前K大元素中最小的元素,将所有元素过滤一遍,遇到比堆顶大的元素便替换当前堆顶。下面第一搏也给出了不使用已有的优先队列,通过自定义siftUp和siftDown方法实现方式。一发入魂O(nlog(k))请注意,你需要找的是数组排序后的第。个最大的元素,而不是第。.原创 2022-07-23 10:44:47 · 518 阅读 · 0 评论 -
LeetCode_Array_42. Trapping Rain Water 接雨水【双指针】【Java】【困难】
从暴力到双指针解决接雨水,细节真的很细原创 2022-06-23 08:50:17 · 191 阅读 · 0 评论 -
LeetCode_Sorting_347. Top K Frequent Elements 前 K 个高频元素【找规律,桶思想】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏第二搏一,题目描述英文描述Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.中文描述给你一个整数数组nums和一个整数k,请你返回其中出现频率...原创 2022-05-22 10:16:20 · 164 阅读 · 1 评论 -
LeetCode_BinaryTree_337. House Robber III 打家劫舍 III【动态规划】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏第二搏一,题目描述英文描述The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.Besides the root, each house has one and only .原创 2022-05-19 23:46:55 · 280 阅读 · 0 评论 -
LeetCode_Array_312. Burst Balloons 戳气球【动态规划】【Java】【困难】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏一,题目描述英文描述You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.If .原创 2022-05-19 12:10:47 · 172 阅读 · 0 评论 -
LeetCode_Array_309. Best Time to Buy and Sell Stock with Cooldown 最佳买卖股票时机含冷冻期【动态规划】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏一,题目描述英文描述You are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete as many transaction.原创 2022-05-09 16:06:56 · 114 阅读 · 0 评论 -
LeetCode_String_301. Remove Invalid Parentheses 删除无效的括号【DFS、剪枝】【Java】【困难】
一,题目描述英文描述中文描述给你一个由若干括号和字母组成的字符串s,删除最小数量的无效括号,使得输入的字符串有效。返回所有可能的结果。答案可以按任意顺序返回。示例与说明二,解题思路三,AC代码Java四,解题过程第一搏一开始想法很简单,先遍历一遍字符串,看看多出来多少个右括号,并记录他们的位置。以这些位置作为最后要删除的右括号,依次尝试删除之前出现的右括号,并将结果存入set中,举个例子:s = "()())()"可以看出...原创 2022-05-08 12:40:08 · 288 阅读 · 0 评论 -
LeetCode_Array_300. Longest Increasing Subsequence 最长递增子序列【动态规划】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏第二搏一,题目描述英文描述Given an integer array nums, return the length of the longest strictly increasing subsequence.A subsequence is a sequence that can be derived from an array by dele.原创 2022-04-27 20:12:12 · 787 阅读 · 0 评论 -
LeetCode_Array_279. Perfect Squares 完全平方数【动态规划】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏第二搏一,题目描述英文描述Given an integer n, return the least number of perfect square numbers that sum to n.A perfect square is an integer that is the square of an integer; in other words.原创 2022-04-20 11:58:40 · 339 阅读 · 1 评论 -
LeetCode_Array_240. Search a 2D Matrix II 搜索二维矩阵 II【二分查找、Z字形查找】【Java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一搏第二搏一,题目描述英文描述Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:Integers in each row are .原创 2022-04-19 15:50:45 · 203 阅读 · 0 评论 -
LeetCode_Array_221. Maximal Square 最大正方形【动态规划,模拟】【Java】【中等】
一,题目描述英文描述Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.中文描述在一个由'0'和'1'组成的二维矩阵内,找到只包含'1'的最大正方形,并返回其面积。示例与说明提示:m == matrix.lengthn == matrix[i].length1 <...原创 2022-04-19 13:28:06 · 130 阅读 · 0 评论 -
LeetCode_BinaryTree_50. Binary Tree Maximum Path Sum 二叉树中的最大路径和【递归】【Java】【困难】
一,题目描述英文描述A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.Th原创 2022-02-25 17:45:46 · 125 阅读 · 0 评论 -
LeetCode_Stack_94. Binary Tree Inorder Traversal 二叉树的中序遍历【栈,迭代】【Java】【简单】
目录一,题目描述中文描述二,解题思路三,AC代码Java四,解题过程第一搏一,题目描述中文描述给定一个二叉树的根节点root,返回它的中序遍历。二,解题思路仍然是利用栈和pre节点,每次弹出节点时,用pre记录,表示已经遍历过。弹出的时机需要注意 注意分情况 pre不要初始化为null三,AC代码Javaclass Solution { public List<Integer> inorderT...原创 2022-01-06 15:23:39 · 302 阅读 · 0 评论 -
LeetCode_Math_50. Pow(x, n)【缩小误差,分治】【java】【中等】
分治法实现pow方法,注意精度问题!!!原创 2021-12-20 19:30:30 · 525 阅读 · 0 评论 -
LeetCode_Sorting_23. Merge k Sorted Lists 合并K个升序链表【归并排序,优先队列】【java】【困难】
归并排序中的多路合并,借助优先队列,非常朴实的解法。原创 2021-12-08 15:59:42 · 388 阅读 · 0 评论 -
LeetCode_Sorting_剑指 Offer 51. 数组中的逆序对【归并排序,分治思想】【java】【困难】
归并排序还能这么用?分治思想yyds原创 2021-12-08 15:20:31 · 106 阅读 · 0 评论 -
LeetCode_Queue_239. Sliding Window Maximum 滑动窗口最大值【优先队列,单调队列】【java】【中等】
滑动窗口最大值的优先队列和单调队列解法。队列原来这么好用!!!原创 2021-12-03 21:24:55 · 636 阅读 · 0 评论 -
LeetCode_Math_470. Implement Rand10() Using Rand7() 用 Rand7() 实现 Rand10()【概率模型】【java】【中等】
随机数生成中的概率和效率问题。乍一看感觉有点无聊,但是搞清楚后,方法还是很有参考价值的。原创 2021-11-29 21:24:26 · 186 阅读 · 0 评论 -
LeetCode_Array_11. Container With Most Water 盛最多水的容器【双指针】【java】【中等】
双指针法的妙用,非常合理原创 2021-11-28 17:16:21 · 97 阅读 · 0 评论 -
LeetCode_String_394. 字符串解码 Decode String【字符串,递归】【java】【中等】
这是一道Java递归处理字符串的问题。希望能对递归思想的学习有所帮助。原创 2021-11-28 01:36:29 · 288 阅读 · 0 评论 -
LeetCode_BinaryTree_95. Unique Binary Search Trees II 不同的二叉搜索树 II【递归,搜索树】【java】【中等】
二叉搜索树的递归构建。更深入的了解递归算法原创 2021-11-26 21:03:37 · 377 阅读 · 0 评论 -
LeetCode_Sorting_面试题 17.14. Smallest K LCCI 最小K个数【快速排序,partation优化】【java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一博第二搏一,题目描述英文描述Design an algorithm to find the smallest K numbers in an array.中文描述设计一个算法,找出数组中最小的k个数。以任意顺序返回这k个数均可。示例与说明来源:力扣(LeetCode)链接:https://leetcode-cn.com/problem.原创 2021-11-26 10:37:29 · 301 阅读 · 0 评论 -
LeetCode_Sorting_148. Sort List 排序链表【快速排序试错,归并排序】【java】【中等】
链表排序。使用普通的快速的快速排序会被针对,导致结果超时。归并排序需要定位中间位置,可以考虑使用快慢指针的方法。原创 2021-11-24 11:48:34 · 698 阅读 · 0 评论 -
LeetCode_Sorting_912. Sort an Array 排序数组【快速排序,堆排序,归并排序】【java】【中等】
LeetCode_Sorting_912. Sort an Array 排序数组【快速排序,堆排序,归并排序】【java】【中等】原创 2021-11-21 18:51:24 · 822 阅读 · 0 评论 -
LeetCode_UnionFind_1202. Smallest String With Swaps 交换字符串中的元素【并查集】【java】【中等】
LeetCode_UnionFind_1202. Smallest String With Swaps 交换字符串中的元素【并查集】【java】【中等】原创 2021-11-19 11:11:10 · 527 阅读 · 0 评论 -
LeetCode_UnionFind_947. Most Stones Removed with Same Row or Column 移除最多的同行或同列石头【连通分量,构建图】【java】【中等】
LeetCode_UnionFind_947. Most Stones Removed with Same Row or Column 移除最多的同行或同列石头【连通分量,构建图】【java】【中等】原创 2021-11-18 17:16:44 · 426 阅读 · 0 评论 -
LeetCode_Union Find_990. Satisfiability of Equality Equations 等式方程的可满足性【并查集,路径压缩,字符串处理】【java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一博一,题目描述英文描述You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms:原创 2021-11-11 14:36:18 · 737 阅读 · 0 评论 -
LeetCode_Union Find_547. Number of Provinces 省份数量【并查集,DFS】【java/C++】【中等】
一,题目描述英文描述There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.A province is a group of direc..原创 2021-11-10 23:45:34 · 1159 阅读 · 0 评论 -
LeetCode_Heap_1801. Number of Orders in the Backlog 积压订单中的订单总数【堆,模拟】【java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码Java四,解题过程第一博一,题目描述英文描述You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pric原创 2021-11-10 00:31:04 · 401 阅读 · 0 评论 -
LeetCode_Sorting_1753. Maximum Score From Removing Stones 移除石子的最大得分【脑筋急转弯】【C++】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码C++四,解题过程第一博一,题目描述英文描述You are playing a solitaire game with three piles of stones of sizes a, b, and c respectively. Each turn you choose two different non-empty piles, take one st原创 2021-11-09 10:14:53 · 2331 阅读 · 0 评论 -
LeetCode_Heap_313. Super Ugly Number 超级丑数【堆超时,动态规划】【C++】【中等】
一,题目描述英文描述中文描述超级丑数 是一个正整数,并满足其所有质因数都出现在质数数组 primes 中。给你一个整数 n 和一个整数数组 primes ,返回第 n 个 超级丑数 。题目数据保证第 n 个 超级丑数 在 32-bit 带符号整数范围内。示例与说明来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/super-ugly-number著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出..原创 2021-11-08 20:11:28 · 347 阅读 · 0 评论 -
LeetCode_Heap_264. Ugly Number II 丑数 II【堆,大数处理】【C++/java】【中等】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码C++Java四,解题过程第一博一,题目描述英文描述An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.Given an integer n, return the nth ugly number.中文描述给你一个整数 n ,请你找出并返回第 n 个 丑数 。原创 2021-11-08 14:36:03 · 513 阅读 · 0 评论 -
LeetCode_Heap_295. Find Median from Data Stream 数据流的中位数 【堆,中位数】【C++/java】【困难】
目录一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码C++Java四,解题过程第一博一,题目描述英文描述The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle value...原创 2021-11-07 22:15:13 · 119 阅读 · 0 评论 -
LeetCode_Heap_373. Find K Pairs with Smallest Sums 查找和最小的K对数字 【堆】【C++/java】【中等】
一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码C++Java四,解题过程第一博借助优先队列——小根堆,双重循环将每一个可能的结果放进去,然后返回队列中的内容。class Solution { public List<List<Integer>> kSmallestPairs(int[] nums1, int[] nums2, int k) { List<List&l..原创 2021-11-07 10:52:29 · 176 阅读 · 0 评论 -
LeetCode_Heap_703. Kth Largest Element in a Stream 数据流中的第 K 大元素 【堆】【C++/java】【简单】
一,题目描述英文描述中文描述示例与说明二,解题思路三,AC代码C++class KthLargest {public: priority_queue<int, vector<int>, greater<int>> queue; int k; KthLargest(int k, vector<int>& nums) { this->k = k;原创 2021-11-05 14:12:51 · 132 阅读 · 0 评论 -
LeetCode刷题记录汇总~持续更新ing【LeetCode_Array_42. 接雨水】
一,数组编号 题目 题解 标签 难度 1 54. Spiral Matrix LeetCode_Array_54. Spiral Matrix (C++) 找规律 2 55. Jump Game LeetCode_Array_55. Jump Game (C++) 找规律 3 56. Merge Intervals LeetCode_Array_56. Merge Intervals C++...原创 2021-11-04 14:12:06 · 4407 阅读 · 0 评论 -
LeetCode_Heap_剑指 Offer 40. 最小的k个数 【堆,泛型实现,自定义比较器】【C++/java】【简单】
一,题目描述英文描述English description is not available for the problem. Please switch to Chinese.中文描述输入整数数组 arr ,找出其中最小的 k 个数。例如,输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。示例与说明限制:0 <= k <= arr.length <= 10000 0 <= arr[i]<= 10...原创 2021-11-04 11:12:25 · 288 阅读 · 0 评论