Skip to content

Commit 27c8d0f

Browse files
author
zhaoliang
committed
arts week 1 modify
1 parent 5d211e3 commit 27c8d0f

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

_posts/arts/2019-04-04-arts_week_1.md

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tags: arts
1414
1515
> **本周提纲:**
1616
> 1. Algorithm: 最长回文子串
17-
> 2. Review: Go语言中什么时候该使用
17+
> 2. Review: 什么时候以及为什么使用最少使用(LFU)缓存与Golang中的实现
1818
> 3. Tip: 一个vim插件`vim-surround`使用
1919
> 4. Share: 我必须告诉大家的MySQL优化原理
2020
@@ -74,38 +74,6 @@ class Solution:
7474

7575
[When and Why to use a Least Frequently Used (LFU) cache with an implementation in Golang](https://ieftimov.com/post/when-why-least-frequently-used-cache-implementation-golang/)
7676

77-
**一个谷歌工程师编码解决问题的过程**
78-
79-
给出的例子:
80-
> 给定两个字符串`sourceString``searchString`,返回`sourceString`第一次出现`searchString`的位置,如果不包含`searchString`则返回`-1`
81-
82-
解决的过程:
83-
84-
1. 画出来
85-
拿到问题就开始编码,可能是一种低效的解决问题的方式,作者建议我们首先要分析问题,甚至不要使用写代码的方式来思考问题,把问题画下来,针对一些具体的问题来画出解决的方案(算法)。
86-
87-
2. 写出解决的逻辑步骤
88-
用语言描述需要解决的问题步骤:
89-
> 1. 从字符串的开头开始扫描
90-
> 2. 查找`searchString`长度的字符串数组
91-
> 3. 找到返回当前字符串的数组下标
92-
> 4. 如果查询到最后没找到则返回`-1`
93-
94-
3. 伪代码
95-
```
96-
for each index in sourceString,
97-
N = searchString.length
98-
POSSIBLE_MATCH = sourceString[index to index+N]
99-
if POSSIBLE_MATCH === searchString:
100-
return index
101-
return -1
102-
```
103-
4. 转换成代码
104-
这一步可能存在一些实际的函数和方法的使用问题,完成主要的逻辑后再来回过头处理这些需要解决的细节问题
105-
5. 明确代码中每一步的逻辑
106-
每一句代码都要明确它的目的,否则这很可能会是以后冒出bug的地方
107-
> 就像前面的 **Algorithm**部分的代码`tempMaxLen = index - i# tempMaxLen = index - i + 1`,以前有个`+1`的运算,如果Hash表中的当前字符的历史位置在现在统计子字符串起始位置之后需要那么新的自字符串的长度为当前的新的字符位置`index` - `i`,为什么不`+1`(上面的if的逻辑中有`+1`),就是因为`startCharIndex = i + 1`(这里`+1`了)
108-
10977
## Tip
11078
介绍一个vim的快速添加‘环绕字符’(eg: '',"",xml标签),省去了来回移动光标的操作
11179
[vim-surround](https://github.com/tpope/vim-surround)

0 commit comments

Comments
 (0)