随笔分类 -  算法

摘要:题目:【https://leetcode.cn/problems/median-of-two-sorted-arrays/?envType=study-plan-v2&envId=top-interview-150】 一道困难题,常规思路不难,但是真的难写,边界要仔细思考。 下面是我第一轮的思路,虽 阅读全文
posted @ 2025-06-05 14:39 J&YANG 阅读(10) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/binary-tree-maximum-path-sum/description/?envType=study-plan-v2&envId=top-interview-150】 又一道困难题目,自行顺利解决,记录一下自己思路。 树形D 阅读全文
posted @ 2025-06-04 10:13 J&YANG 阅读(15) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/h-index/?envType=study-plan-v2&envId=top-interview-150】 其实就是理解成两个维度,找到两个维度在相互制衡情况下的公共最大值。 1 class Solution { 2 public 阅读全文
posted @ 2025-06-03 18:00 J&YANG 阅读(10) 评论(0) 推荐(0)
摘要:力扣53. 最大子数组和:【https://leetcode.cn/problems/maximum-subarray/description/】 经典的dp + 空间优化,代码如下 1 class Solution { 2 public: 3 int maxSubArray(vector<int> 阅读全文
posted @ 2025-06-03 16:11 J&YANG 阅读(14) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/majority-element/?envType=study-plan-v2&envId=top-interview-150】 这个题目跟找数量最多的数字有区别,这里面的算法也属于单独适合这个题的算法。 通常来说,看到这种题目第一想 阅读全文
posted @ 2025-06-03 09:55 J&YANG 阅读(10) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/candy/description/?envType=study-plan-v2&envId=top-interview-150】 想了一个办法,依次向后遍历,遇到下降(不包含相等)的情况,就将其置为1,并且开始第二层循环,从当前位置 阅读全文
posted @ 2025-05-28 15:01 J&YANG 阅读(11) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/minimum-path-sum/description/?envType=study-plan-v2&envId=top-interview-150】 直接看出来是二维dp,压缩至一维存储,然后就通过了 1 #define NUM_ 阅读全文
posted @ 2025-05-27 10:25 J&YANG 阅读(10) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/jump-game-ii/?envType=study-plan-v2&envId=top-interview-150】 当时首先想到的是dp,也写出了一个dp算法,不过写的时候就知道,这个方法时间复杂度在最差的情况下,趋近于n的平方 阅读全文
posted @ 2025-05-26 14:23 J&YANG 阅读(15) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/jump-game/?envType=study-plan-v2&envId=top-interview-150】 比较容易想到的思路,记录一下 1 class Solution { 2 public: 3 bool canJump( 阅读全文
posted @ 2025-05-22 14:02 J&YANG 阅读(6) 评论(0) 推荐(0)
摘要:经典题目,也比较简单,不多说,记录一下自己的思路 题目:【https://leetcode.cn/problems/reverse-linked-list/】 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * 阅读全文
posted @ 2025-05-13 09:51 J&YANG 阅读(5) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/minimum-size-subarray-sum/solutions/305704/chang-du-zui-xiao-de-zi-shu-zu-by-leetcode-solutio/?envType=study-plan-v2& 阅读全文
posted @ 2025-05-12 13:38 J&YANG 阅读(7) 评论(0) 推荐(0)
摘要:记录一下自己思路,排除直接api的做法,类似双指针吧,将头和尾都确定出来,然后加入到结果中,以此类推。 题目:【https://leetcode.cn/problems/reverse-words-in-a-string/description/?envType=study-plan-v2&envI 阅读全文
posted @ 2025-05-12 10:34 J&YANG 阅读(2) 评论(0) 推荐(0)
摘要:题目:【https://leetcode.cn/problems/unique-paths-ii/?envType=study-plan-v2&envId=top-interview-150】 下面这个深度优先搜索超时了。。。不过还是记录一下,看看自己失败在那里。。。 1 class Solutio 阅读全文
posted @ 2025-05-09 17:12 J&YANG 阅读(8) 评论(0) 推荐(0)
摘要:归根结底还是要辅助空间,创建一个返回值的vector,另外sort可以直接排序这种复杂纯数据,即使是二维的,也会按照先第一维,然后第二维的顺序,排序正确。 题目:【https://leetcode.cn/problems/merge-intervals/description/?envType=st 阅读全文
posted @ 2025-05-09 16:13 J&YANG 阅读(4) 评论(0) 推荐(0)
摘要:单链表真的遭罪,不过有一个技巧,就是创建一个head,这样便于处理首元素就需要删除的情况。 题目:【https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/?envType=study-plan-v2&envId=top- 阅读全文
posted @ 2025-05-09 14:34 J&YANG 阅读(9) 评论(0) 推荐(0)
摘要:题目用双指针方法很好想思路,只不过有一种情况要排除,就是链表元素数量==倒数n的时候,要在判断到快指针为NULL的时候,直接返回head->next,排除这种情况之后,其它情况就很好处理了。 题目:【https://leetcode.cn/problems/remove-nth-node-from- 阅读全文
posted @ 2025-05-09 10:10 J&YANG 阅读(11) 评论(0) 推荐(0)
摘要:① 刚开始的思路是哈希表+一个环形缓冲区,但是看到条件中可以重复,那这样可就麻烦了,另外,真的没有想到哈希表中存地址,另外list中既要保存key,也要保存value,按理说只有value就可以,但是要考虑一个点,就是size达到capacity的时候,要通过key才能找到删除哈希表中的哪一个; ② 阅读全文
posted @ 2025-05-08 11:15 J&YANG 阅读(14) 评论(0) 推荐(0)
摘要:虽然是难题,代码量并不多,但是高效率的思路真的很难想到 题目:【https://leetcode.cn/problems/find-median-from-data-stream/description/?envType=study-plan-v2&envId=top-interview-150】 阅读全文
posted @ 2025-05-07 11:17 J&YANG 阅读(9) 评论(0) 推荐(0)
摘要:一天懵一次,次次不一样,这个题目是简单题,但是前提是必须看出来存在环,看不出来这一点就莫得了 题目:【https://leetcode.cn/problems/happy-number/description/?envType=study-plan-v2&envId=top-interview-15 阅读全文
posted @ 2025-05-06 09:58 J&YANG 阅读(6) 评论(0) 推荐(0)
摘要:字符串题目,遭罪 题目:【https://leetcode.cn/problems/zigzag-conversion/?envType=study-plan-v2&envId=top-interview-150】 1 class Solution { 2 public: 3 string conv 阅读全文
posted @ 2025-04-27 15:28 J&YANG 阅读(6) 评论(0) 推荐(0)