1. Algorithm
给你一个字符串 S、一个字符串 T 。请你设计一种算法,可以在 O(n) 的时间复杂度内,从字符串 S 里面找出:包含 T 所有字符的最小子串。
示例:
输入:S = "ADOBECODEBANC", T = "ABC" 输出:"BANC"提示:
如果 S 中不存这样的子串,则返回空字符串 “”。
如果 S 中存在这样的子串,我们保证它是唯一的答案。来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/minimum-window-substring
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
与上周一样,又是一道滑动窗口的题目。这次我自己想了好久,虽然还是没能完全写出来,不过比上周理解又加深了一步。
这时候又得感叹一下,古人说知易行难,我等凡人有时候感到的是:知难行难。
class Solution:
def minWindow(self, s: str, t: str) -> str:
left = 0
right = 0
valid = 0
need = {}
window = {}
for chart in t:
need[chart] = 1 + need.get(chart, 0)
start = 0
t_len = float('inf')
# 扩展窗口
while right < len(s):
c = s[right]
right += 1
if c in need.keys():
window[c] = 1 + window.get(c, 0)
if window[c] == need[c]:
valid += 1
while valid == len(need):
if right - left < t_len:
start = left
t_len = right - left
d = s[left]
left += 1
if d in window.keys():
if window[d] == need[d]:
valid -= 1
window[d] -= 1
return "" if t_len == float('inf') else s[start:start+t_len]
2. Review: What Programmers Can Do to Write Better Code
2.1 背景介绍
2.1.1 关联人
背景知识
NATO conference on software engineering
著名的北约软件工程会议,在1968、1969年为了解决第一次软件危机而召开。
此次会议提出了软件危机一词,同时提出解决方案:软件工程。
2.2 生词记录
standout points
For me, some of the standout points were the realisations that software development is iterative, experimental/learning focused, practitioner lead, and best done in small teams.
-
standout points,该短语没有在韦伯词典中找到
-
standout在Google翻译的英文解释是:
a person or thing of exceptional ability or high quality.
-
在韦伯词典中解释是
one that is prominent or conspicuous especially because of excellence
-
都有卓越、突出的意思(褒义)
constrains
The activities and constrains are radically different to previous activities.
-
约束的意思
-
韦伯词典的释义
to force by imposed stricture, restriction, or limitation
to restrict the motion of (a mechanical body) to a particular mode -
谷歌翻译的释义
compel or force (someone) to follow a particular course of action.
coupling、cohesion
Why do you think that understanding design fundamentals such as coupling and cohesion is important?
这两个单词都有凝聚、聚合的意思,但是区别是什么呢?
-
coupling的英文释义
the act of bringing or coming together
a device for connecting parts of machinery.
the pairing of two items. -
cohesion的英文释义
the act or state of sticking together tightly
the action or fact of forming a united whole.
如果直接查Google翻译,可以看到coupling的中文就是耦合的意思,cohesion是凝聚的意思。所以我们平常说的高内聚、低耦合,用英文说就是low coupling,high cohesion。
为此找到了一篇英文文章Software Engineering | Coupling and Cohesion讲解coupling与cohesion之间的差别。
2.3 Literature Note
-
软件开发已经是一个有着几十年历史的行业了,但我们面对着业务复杂度的提升,而这也带来了软件复杂度的提升
-
规模的提升(类、模块、组件)带来了复杂度的提升,而这些组件的因为组合又带来了更高的复杂度
-
抽象、分离关注点是解决复杂度问题的好办法
-
We can also see this with tooling now where the likes of Jetbrains don’t lock you into a contract for their product; they lock you in by providing a great product that increases productivity.
Jetbrains是一个非常好的例子,它告诉我们产品本身的价值所在,使用我就能提升你的生产力。用久了Jetbrains产品之后在用回Eclipse就有种强烈的“不适应”。
但面对的难题是,切换一个产品是有成本的,你怎么让他开始使用你的产品?我想这也就是Jetbrains提供了一个社区版IDEA的原因。 -
重新阅读代码,不只是自己写的代码,还有别人的代码。代码一个软件开发者最终落地的东西。你的学习、你读过的技术书籍、博客、与人的交流在我们脑海中留下印象之后再去看以前的代码,总会有的新想法,总会让我们变得更好一点
3. Tip: 时间轮
最近项目上需要实现延迟任务的功能,对比了几个方案,最终决定使用时间轮。方案对比以及技术细节因为还没写完,就先留坑在此。
4. Share:分享一下万维刚的《万万没想到》
这不是网剧《万万没想到》,是科普作家万维刚所写的,恰好书名也是《万万没想到》。
万维刚老师以前是做物理学研究的,因为喜欢写文章,后来被罗辑思维团队挖过去,现在每年都会开一门《精英日课》。《万万没想到》这本书是2016年出版的,看介绍得了不少奖,我阅读过程中只能感叹:名副其实。
未必说这本书中的观点是我从前都未接触过的,比如关于学习的节奏应该是什么样的,比如穷人思维是怎么一回事,很多观点如果是16年的时候可能觉得很心,但四年过去了,很多观点已经要变成“常识”了。
我所感叹的是他阅读范围之广。人家说真正读懂了书就能“观其大略”,万维刚老师就是那种会读书的人吧。
本文探讨了滑动窗口算法在寻找字符串中最小子串的应用,并深入分析了如何通过理解设计基本原则如耦合和内聚来提升代码质量。
3408

被折叠的 条评论
为什么被折叠?



