摘要:
problem:https://leetcode.com/problems/longest-repeating-character-replacement/ 维护一个最多包含k个额外字符的滑动窗口。需要记录当前出现次数最多字符的出现次数来判断窗口是否合法,如果超过了,就把首指针向后挪一位,同时更新最 阅读全文
posted @ 2019-08-11 22:14
fish1996
阅读(111)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/minimum-window-substring/ 滑动窗口题。维护一个包含t中所有字符的最小滑动窗口,首先用一个hashmap记录所有t中的字符和出现次数,在s中每遇到一次计数器加一,找到了符合条件的窗口后,尝试向右移动窗 阅读全文
posted @ 2019-08-11 21:39
fish1996
阅读(139)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/permutation-sequence 求第k个排列数。数学解法,可以找一下规律。比如对于1234的排列数,一共有24种。我们从左到右依次决定排列数是哪些。首先第一个数有4种可选的,一共有24种,那么每种就是6个,我们用 阅读全文
posted @ 2019-08-11 21:18
fish1996
阅读(89)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/permutations/ 输出所有排列数。递归中,最快的方法是直接交换,实际上执行的是选择操作,选择了一个数据后,把它交换到前面;可以保证下一次选择不会包含着一数字,并且数字被选择的概率都是相等的。 阅读全文
posted @ 2019-08-11 18:26
fish1996
阅读(107)
评论(0)
推荐(0)
摘要:
前序遍历: 中序遍历: 后序遍历: 阅读全文
posted @ 2019-08-11 17:53
fish1996
阅读(344)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/find-peak-element/ 根据下标二分搜索。每次检查mid左右两个数和mid的关系,决定如何进行下一步。 阅读全文
posted @ 2019-08-11 17:32
fish1996
阅读(155)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 经典二分搜索题。要点是改变low或high的时候把当前数字mid也包含进来,因为它也可能是结果。 阅读全文
posted @ 2019-08-11 16:38
fish1996
阅读(110)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/search-a-2d-matrix-ii 经典双指针二分查找题目。 阅读全文
posted @ 2019-08-11 16:20
fish1996
阅读(102)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/next-greater-node-in-linked-list/ 维护递减的单调栈。这道题对象是链表,不像数组可以快速通过下标索引,所以比较方便的做法是在栈中同时记录数字和对应的下标,并且默认填0,如果找到了比它大的第一个 阅读全文
posted @ 2019-08-11 16:05
fish1996
阅读(116)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/largest-rectangle-in-histogram 经典单调栈题目。维护递增的单调栈,当发现当前数字比栈顶要小的时候,此时栈顶元素是最大的(大于栈里的下一个元素,也大于当前元素),所以可以计算以当前栈顶元素为高的矩 阅读全文
posted @ 2019-08-11 15:12
fish1996
阅读(89)
评论(0)
推荐(0)
摘要:
这一次终于没有提交WA了。 1154. Day of the Year 简单题。打印一年到现在的天数,区分闰年即可。// 不要问我run, ping是啥意思 = =。 1155. Number of Dice Rolls With Target Sum 中等题,动态规划。给你d个骰子,包含数字为1~ 阅读全文
posted @ 2019-08-11 13:46
fish1996
阅读(211)
评论(0)
推荐(0)
摘要:
problem:https://leetcode.com/problems/find-the-duplicate-number/ 查找是否存在环。快指针走2步,慢指针走1步,相遇则存在环。设慢指针走了路程s,则快指针走了2s,环长度为s。若环的起始位置为d,则慢指针的位置在起始位置过一点的地方,它只 阅读全文
posted @ 2019-08-11 02:48
fish1996
阅读(198)
评论(0)
推荐(0)
摘要:
problem: https://leetcode.com/problems/search-in-rotated-sorted-array/ 二分搜索题。检查二分后的半段是否满足递增条件,如果满足且数据落在这一区间,就在这一区间查找,否则到另一区间查找。 阅读全文
posted @ 2019-08-11 02:07
fish1996
阅读(124)
评论(0)
推荐(0)
摘要:
最后一题比赛快结束的时候想到怎么做了(通过WA的数据猜出来的),比赛后10分钟做出来的。最终做了3题,时间1个小时左右吧。 1150. Check If a Number Is Majority Element in a Sorted Array 这道题理论应该用二分,但是数据量很小(1000),所 阅读全文
posted @ 2019-08-11 00:29
fish1996
阅读(278)
评论(0)
推荐(0)

浙公网安备 33010602011771号