<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[chaochen1407的专栏]]></title><description><![CDATA[]]></description><link>https://blog.csdn.net/chaochen1407</link><language>zh-cn</language><generator>https://blog.csdn.net/</generator><copyright><![CDATA[Copyright &copy; chaochen1407]]></copyright><item><title><![CDATA[3008. Find Beautiful Indices in the Given Array II]]></title><link>https://blog.csdn.net/chaochen1407/article/details/135552935</link><guid>https://blog.csdn.net/chaochen1407/article/details/135552935</guid><author>chaochen1407</author><pubDate>Fri, 26 Jan 2024 15:30:35 +0800</pubDate><description><![CDATA[当我们走到f这个数字的时候，在haystack那边我们已经走到了最后一个d，但是d和f匹配不上，然后已知的是之前匹配过了abc了，所以j = next[j - 1] 会返回的，不是上一个abc最后的位置c，而是走完了上一次abc之后的东西。假设扫描haystack的指针是i，扫描needle的指针是j，在匹配不上的时候，kmp的处理逻辑i不动，是 j = next[j - 1]，这里的意思指的是。这题最难的部分其实就是第一个部分的strstr，根据数据量的要求，只能是kmp（或者更高级的）。]]></description><category></category></item><item><title><![CDATA[Task Scheduler]]></title><link>https://blog.csdn.net/chaochen1407/article/details/126465401</link><guid>https://blog.csdn.net/chaochen1407/article/details/126465401</guid><author>chaochen1407</author><pubDate>Mon, 22 Aug 2022 15:28:45 +0800</pubDate><description><![CDATA[如果仅考虑A的情况，那么出任务的结果就是AIIAIIAIIA，其中I表示idle的意思你可以发现在这种情况下，idle出现的次数就是（A出现的次数 - 1）* n。譬如说4个A之间，只有三个idle空间，这三个idle空间你不可能再塞4个B，所以你能减掉的数目是min(idle区间数，task出现次数），也就是你即使遍历到B，你也不能从idle剩余数目里减掉4个，只能减掉3个。你可以看出来剩余的tasks的数量超过了idle的数目了，而且task的种类也超过了中间的idle的数目。我们随便取一个就可以了。]]></description><category></category></item><item><title><![CDATA[Longest Repeating Character Replacement]]></title><link>https://blog.csdn.net/chaochen1407/article/details/126181248</link><guid>https://blog.csdn.net/chaochen1407/article/details/126181248</guid><author>chaochen1407</author><pubDate>Fri, 05 Aug 2022 17:21:11 +0800</pubDate><description><![CDATA[Window只扩大不缩小。譬如说当K = 3的时候，你有一个abcdffesdaf，那么譬如abcd或者cdffe之类的都是符合条件的Window，因为abcd有四个字符，出现最多的单个字符的长度也只有1，那么你可以同时replace 4 - 1 = 3个使之成为一个有效的window，cdffe也类似，出现最多的单个字符是f，出现了两次，+3 = 5，也是有效的。如果你想一直维持一个有效的window，那么你必须在遍历的时候永远知道当前window里出现最多的字符是什么，出现最多的次数是多少。...]]></description><category></category></item><item><title><![CDATA[[LC] 489. Robot Room Cleaner]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103572878</link><guid>https://blog.csdn.net/chaochen1407/article/details/103572878</guid><author>chaochen1407</author><pubDate>Tue, 17 Dec 2019 15:45:12 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/robot-room-cleaner/





这一题，我第一次面fb的时候，被挂过。所以还是想过一下的。这题只能dfs做，因为它的限制就是你只能一格格一步步走，没办法像bfs所需要的那样跳着格子一层层的走。所以你要做的就是每到一个格子，就四个方向走，同时用某种方式记录你走过的位置以免重复走，但是你这玩意儿，它还需要回头走回你来的方向的...]]></description><category></category></item><item><title><![CDATA[[LC] 480. Sliding Window Median]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103572767</link><guid>https://blog.csdn.net/chaochen1407/article/details/103572767</guid><author>chaochen1407</author><pubDate>Tue, 17 Dec 2019 02:08:15 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/sliding-window-median/



这题就是这一题的延伸版本：https://blog.csdn.net/chaochen1407/article/details/82688222

可以直接在这一题的原做法上加一个删除的操作即可。就是当这个window走过一个元素，就从两边的queue中某个删除掉就可以了。但是从prio...]]></description><category></category></item><item><title><![CDATA[[LC]463. Island Perimeter]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103560421</link><guid>https://blog.csdn.net/chaochen1407/article/details/103560421</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 12:45:15 +0800</pubDate><description><![CDATA[这题是easy题，所以很easy。不过，还是有点可以取巧的地方。
最开始的最naive的做法就是走完整个方阵，走到每个方格的时候，首先设置基础周长为4，因为周围四个边。然后看上下左右四个方向有没有方格， 有的话就减一。然后得到的数字加到结果里即可。根据这个算法可以得到代码如下：



    public int islandPerimeter(int[][] grid) {
       ...]]></description><category></category></item><item><title><![CDATA[[LC] 452. Minimum Number of Arrows to Burst Balloons]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103560316</link><guid>https://blog.csdn.net/chaochen1407/article/details/103560316</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 12:36:16 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/



这一题让我想起了另一题，如果在一群schedule里面得到所需的最少的meeting room。https://blog.csdn.net/chaochen1407/article/details/81282319

那一题本质就是找最大的ove...]]></description><category></category></item><item><title><![CDATA[[LC] 449. Serialize and Deserialize BST]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103556982</link><guid>https://blog.csdn.net/chaochen1407/article/details/103556982</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 10:00:27 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/serialize-and-deserialize-bst/



一般来说serialize和deserialize的要求就是这个数据能够完整且表示唯一的数据结构。有点像充要条件的意思。对于一般的binary tree，充要条件可能为一个preorder的数组和inorder的数组，也可能为一个inorder的数组和一个postorde...]]></description><category></category></item><item><title><![CDATA[[LC] 442. Find All Duplicates in an Array]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103556487</link><guid>https://blog.csdn.net/chaochen1407/article/details/103556487</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 09:08:18 +0800</pubDate><description><![CDATA[看到最初始的条件，1 &lt;= a[i] &lt;= n (n = size of array)。我最开始能够想到的是https://blog.csdn.net/chaochen1407/article/details/43230993

上面这种做法的根本就是让众神归位，就是把数字放到放到它该呆的位置，也就是把num放到arr[num - 1]，然后上面那题，是找到不存在的数字，而这一题，...]]></description><category></category></item><item><title><![CDATA[[LC] 438. Find All Anagrams in a String]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103556358</link><guid>https://blog.csdn.net/chaochen1407/article/details/103556358</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 08:02:47 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/find-all-anagrams-in-a-string/



这一题，其实和很多题目都一样或者类似，先通过字符串p算出一个字符table， 然后就是维持一个window，数一下window里面各个字符有多少，然后匹配到p字符串的字符table，如果相同就记录。代码如下：


    public List&lt;Integer&gt...]]></description><category></category></item><item><title><![CDATA[[LC] 430. Flatten a Multilevel Doubly Linked List]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103556340</link><guid>https://blog.csdn.net/chaochen1407/article/details/103556340</guid><author>chaochen1407</author><pubDate>Mon, 16 Dec 2019 07:54:02 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/

这题其实是非常直观的dfs题目，每次遇到child的时候，进入下一层dfs，这个dfs需要返回两个点，一个是child list的头，另一个是child list的尾。此时遍历到的这个节点的next就会成为child list的头，child list...]]></description><category></category></item><item><title><![CDATA[[LC] 428. Serialize and Deserialize N-ary Tree]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103551577</link><guid>https://blog.csdn.net/chaochen1407/article/details/103551577</guid><author>chaochen1407</author><pubDate>Sun, 15 Dec 2019 18:46:40 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree/

实话说在我心目中leetcode里面的题目，有些hard是属于需要很巧妙的解法，有些hard是属于很烦但是不太涉及很巧妙的算法。这一题就属于很麻烦的那一种。

其实这样的serialize和deserialize核心算法还是bfs或者dfs，题目的描述里其实...]]></description><category></category></item><item><title><![CDATA[[LC] 426. Convert Binary Search Tree to Sorted Doubly Linked List]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103547350</link><guid>https://blog.csdn.net/chaochen1407/article/details/103547350</guid><author>chaochen1407</author><pubDate>Sun, 15 Dec 2019 12:22:09 +0800</pubDate><description><![CDATA[BST换排好序的任何数据结构用脚趾头想都应该是inorder的dfs。这里也就是dfs中间穿插一些前后连接的操作就行了。
给出两种解法，一个是递归做的，一个是用Stack做的。（意想不到的是递归的比Stack的要快）


    public Node treeToDoublyList(Node root) {
        if (root == null) return null;
...]]></description><category></category></item><item><title><![CDATA[[LC] 419. Battleships in a Board]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103546814</link><guid>https://blog.csdn.net/chaochen1407/article/details/103546814</guid><author>chaochen1407</author><pubDate>Sun, 15 Dec 2019 11:19:04 +0800</pubDate><description><![CDATA[正常来说，这种找一个图里面有多少个island的题目都是用什么dfs来做的。就是dfs走遍一个island或者battleship然后mark visited之类的。这题也是可以的。当然follow up就肯定不是这样了。这题给了一个很给力的条件，就是所有的battleship都是一条线。要不就是直的，要不就是横的，并且任意两条船之间，都有空位，不能相邻。所以这个时候，其实我们只需要找到每条b...]]></description><category></category></item><item><title><![CDATA[[LC] 417. Pacific Atlantic Water Flow]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103168121</link><guid>https://blog.csdn.net/chaochen1407/article/details/103168121</guid><author>chaochen1407</author><pubDate>Wed, 20 Nov 2019 18:22:34 +0800</pubDate><description><![CDATA[这一题是一题有点典型又有点非典型的图论题

典型在于它除了BFS或者DFS然后记录visited之外没有什么高级货。
非典型在于一般我们都在图内的某些特异点进行dfs或者bfs，我最开始考虑的是图上每个点做dfs然后从中间点往两边海域自下而上的dfs，一旦遇到比自己高的点就停下来，如果遇到边界就自下而上返回true这样。可是这会存在一个无法解决的问题就是，如果存在同样高度的点，你是没办法把它记录成...]]></description><category></category></item><item><title><![CDATA[[LC] 416. Partition Equal Subset Sum]]></title><link>https://blog.csdn.net/chaochen1407/article/details/103105526</link><guid>https://blog.csdn.net/chaochen1407/article/details/103105526</guid><author>chaochen1407</author><pubDate>Sun, 17 Nov 2019 08:32:40 +0800</pubDate><description><![CDATA[这题是0-1背包问题的变种，类似的还有另一题是完全背包问题是https://blog.csdn.net/chaochen1407/article/details/90767890。当初没认出来它其实是一个完全背包问题。主要是自己对背包问题也没有很好的学习过。

这题需要一定的转换才能看成是一个背包问题。它题意的意思是可以把这个array变成两个不重叠的部分，两个部分的和是一样的。所以，任意一...]]></description><category></category></item><item><title><![CDATA[[LC] 328. Odd Even Linked List]]></title><link>https://blog.csdn.net/chaochen1407/article/details/102959087</link><guid>https://blog.csdn.net/chaochen1407/article/details/102959087</guid><author>chaochen1407</author><pubDate>Thu, 07 Nov 2019 17:39:12 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/odd-even-linked-list/

很久没有试过不看提示自己很快解决一道medium题了，今天终于搞定了一道。也不知道是不是因为太简单了。。
这题一个很直接的一个想法就是将链表先分拆成两条链，一条odds链一条even链然后odds链连接even链就可以了。关键就是如何分拆了。我看到这题目的时候让我有点想到当年我遇到的第一条...]]></description><category></category></item><item><title><![CDATA[[LC] 405. Convert a Number to Hexadecimal]]></title><link>https://blog.csdn.net/chaochen1407/article/details/102958094</link><guid>https://blog.csdn.net/chaochen1407/article/details/102958094</guid><author>chaochen1407</author><pubDate>Thu, 07 Nov 2019 16:48:08 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/convert-a-number-to-hexadecimal/

嗯，就因为开头那一句负数参考补码，我研究了半天的补码。然后我发现...其实根本就不是那么回事。
如果这一题不允许负数的话，最直观的想法就是不停的模16然后除以16即可。然后看了看补码，想该怎么变换数字才能够继续这种无脑模16除16，发现这样做真的很复杂。所以换一种思维...]]></description><category></category></item><item><title><![CDATA[[LC] 398. Random Pick Index]]></title><link>https://blog.csdn.net/chaochen1407/article/details/102956660</link><guid>https://blog.csdn.net/chaochen1407/article/details/102956660</guid><author>chaochen1407</author><pubDate>Thu, 07 Nov 2019 16:07:03 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/random-pick-index/

Well.. 这一题，直白的方法太多了。譬如直接扣一个Map&lt;Integer, List&lt;Integer&gt;&gt;的cache，然后每次就先从map里面找到那个index list，然后用Random.nextInt选出来就好。这个方法构造函数是O(n)的，然后pick是O(1...]]></description><category></category></item><item><title><![CDATA[[LC] 394. Decode String]]></title><link>https://blog.csdn.net/chaochen1407/article/details/102953410</link><guid>https://blog.csdn.net/chaochen1407/article/details/102953410</guid><author>chaochen1407</author><pubDate>Thu, 07 Nov 2019 15:32:47 +0800</pubDate><description><![CDATA[https://leetcode.com/problems/decode-string/

这一题给的条件太友善了，主要是没有3a或者2[4]这样的输出，这样逻辑判断就很简单了。因为中括号允许内部嵌套，这样的话最好的方式还是自下而上的dfs递归会比较方便。用一个全局的遍历计数器，然后基本就是分几个case

1. 遇到0 ~ 9，就算进一个counter里表示对下一层递归返回的字符串重复多少次...]]></description><category></category></item></channel></rss>