<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[ykdsir的博客]]></title><description><![CDATA[渣渣程序员，执着于算法却并不精通。没想过改变世界，只想着岁月静好。]]></description><link>https://blog.youkuaiyun.com/ykd14</link><language>zh-cn</language><generator>https://blog.youkuaiyun.com/</generator><copyright><![CDATA[Copyright &copy; ykd14]]></copyright><item><title><![CDATA[Leetcode Weekly Contest 196]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/107142033</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/107142033</guid><author>ykd14</author><pubDate>Sun, 05 Jul 2020 17:40:15 +0800</pubDate><description><![CDATA[5452. 判断能否形成等差数列
思路：
排序后取前两个数的差，依次检查是否满足等差。
注意提示中给出的数组长度大于等于2，所以不需要考虑边界条件。
class Solution:
    def canMakeArithmeticProgression(self, arr: List[int]) -&gt; bool:
        arr = sorted(arr)
        num = arr[1] - arr[0]
        pre = arr[1]
        for x in ]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 195]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/107043109</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/107043109</guid><author>ykd14</author><pubDate>Tue, 30 Jun 2020 15:17:10 +0800</pubDate><description><![CDATA[1496. 判断路径是否相交
思路：
按照题目意思模拟即可。
class Solution:
    def isPathCrossing(self, path: str) -&gt; bool:
        path_set = set([(0,0)])
        pre = (0,0)
        for p in path:
            x, y = pre
            if p == 'N':
                y += 1
           ]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 190]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/106312965</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/106312965</guid><author>ykd14</author><pubDate>Sun, 24 May 2020 14:36:39 +0800</pubDate><description><![CDATA[5416. 检查单词是否为句中其他单词的前缀
思路：
直接遍历数组，取前缀匹配满足的第一个字符串即可。前缀匹配可自己手写或直接用接口。
class Solution:
    def isPrefixOfWord(self, sentence: str, searchWord: str) -&gt; int:
        res = -1
        for i, word in enumerate(sentence.split(' ')):
            if word.startswi]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 189]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/106184611</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/106184611</guid><author>ykd14</author><pubDate>Mon, 18 May 2020 00:27:01 +0800</pubDate><description><![CDATA[通过这次周赛，对Python的喜爱又深了一层。
5412. 在既定时间做作业的学生人数
思路：
因为数据量较小并且只查询一次，直接遍历比较即可。
多次查询的话，考虑线段树。
class Solution:
    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -&gt; int:
        res = 0
        for i in range(len(startTime)):
  ]]></description><category></category></item><item><title><![CDATA[Leetcode Bi-Weekly Contest 26]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/106183736</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/106183736</guid><author>ykd14</author><pubDate>Sun, 17 May 2020 23:36:49 +0800</pubDate><description><![CDATA[5396. 连续字符
思路：
用单独的变量记录前一个字符，判断当前字符和前一个字符是否相同，以此来进行计数。
class Solution:
    def maxPower(self, s: str) -&gt; int:
        pre = s[0]
        count = 1
        res = 1
        for x in s[1:]:
            if x == pre:
                count += 1
            el]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 188]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/106042235</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/106042235</guid><author>ykd14</author><pubDate>Sun, 10 May 2020 21:11:07 +0800</pubDate><description><![CDATA[今天的周赛题目挺有意思的。
5404. 用栈操作构建数组
思路：
如果一个数在最后的数组里，只push；不在最后的数组里面，先push再pop
class Solution:
    def buildArray(self, target: List[int], n: int) -&gt; List[str]:
        res = []
        cur = 1
        for x in target:
            while cur != x:
             ]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 187]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/105906143</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/105906143</guid><author>ykd14</author><pubDate>Sun, 03 May 2020 17:32:03 +0800</pubDate><description><![CDATA[5400. 旅行终点站
思路：
直接使用dict记录出度即可
from collections import defaultdict
class Solution:
    def destCity(self, paths: List[List[str]]) -&gt; str:
        res_map = defaultdict(int)
        tmp = set()
    ...]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 186]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/105905972</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/105905972</guid><author>ykd14</author><pubDate>Sun, 03 May 2020 17:21:48 +0800</pubDate><description><![CDATA[1422. 分割字符串的最大得分
思路：
先统计数组中所有为1的数量num，使用l记录左边0的数量，然后从第一个位置开始，依次往后遍历。当前位置为0，则l加1，为1则num减1。
class Solution:
    def maxScore(self, s: str) -&gt; int:
        num = 0
        for x in s:
            if x...]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 185]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/105617447</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/105617447</guid><author>ykd14</author><pubDate>Sun, 19 Apr 2020 16:38:31 +0800</pubDate><description><![CDATA[5388. 重新格式化字符串
思路：
统计字母个数n1和数字个数n2， 如果abs(n1-n2) &gt; 1，不存在满足要求的字符串，返回空串。否则，相邻间隔一次插入就行。
Python代码如下：
class Solution:
    def reformat(self, s: str) -&gt; str:
        res = ""
        ch=""
        num...]]></description><category></category></item><item><title><![CDATA[从集合划分角度分析动态规划]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/105126139</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/105126139</guid><author>ykd14</author><pubDate>Thu, 26 Mar 2020 19:39:39 +0800</pubDate><description><![CDATA[动态规划，有限集中的最优化问题。]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 124]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/87836942</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/87836942</guid><author>ykd14</author><pubDate>Thu, 21 Feb 2019 00:56:31 +0800</pubDate><description><![CDATA[来自个人博客：自娱自乐的精神乐园
993. 二叉树的堂兄弟节点
描述
在二叉树中，根节点位于深度 0 处，每个深度为 k 的节点的子节点位于深度 k+1 处。如果二叉树的两个节点深度相同，但父节点不同，则它们是一对堂兄弟节点。我们给出了具有唯一值的二叉树的根节点 root，以及树中两个不同节点的值 x 和 y。只有与值 x 和 y 对应的节点是堂兄弟节点时，才返回 true。否则，返回 false...]]></description><category></category></item><item><title><![CDATA[Leetcode Weekly Contest 113]]></title><link>https://blog.youkuaiyun.com/ykd14/article/details/84730016</link><guid>https://blog.youkuaiyun.com/ykd14/article/details/84730016</guid><author>ykd14</author><pubDate>Mon, 03 Dec 2018 01:19:33 +0800</pubDate><description><![CDATA[做了几次leetcode的周赛，还是菜的不行，每次基本上就做3道题，偶尔在规定时间内做完了4道题。仅以此记录一下自己每次刷题的一点点思考，慢慢学习。

949. 给定数字能组成的最大时间

该题不是很难，四个数作为4位数不同的排列最多24种，最简单的方式是枚举24种数值，取其中满足条件的最大值即可。
对于 abcd 因此满足条件的值范围 0≤cd≤59 and 0≤ab≤23，例如1234 代表1...]]></description><category></category></item></channel></rss>