引言
在我学习 Vim 的过程中,最具有启发意义的一句话是:
Vim 其实是一门“编程语言”
很早之前我就接触过 Vim,但是当时 Vim 的按键组合对我来说很难记,再加上 Vim 的界面实在太过于复古,于是我就转向了比较现代的文本编辑器。但当我学完 Missing semester 这门课程的时候,我对 Vim 的看法有了改观:它远远不止是一个文本编辑器,各种 Vim 的命令的排列组合更像是在写代码,背后都是有逻辑的!
在我学习 Vim 的过程中,最具有启发意义的一句话是:
Vim 其实是一门“编程语言”
很早之前我就接触过 Vim,但是当时 Vim 的按键组合对我来说很难记,再加上 Vim 的界面实在太过于复古,于是我就转向了比较现代的文本编辑器。但当我学完 Missing semester 这门课程的时候,我对 Vim 的看法有了改观:它远远不止是一个文本编辑器,各种 Vim 的命令的排列组合更像是在写代码,背后都是有逻辑的!
今天又做到了 Leetcode 169. 多数元素 这一道题. 我依稀记得最优的解法叫做什么摩尔投票法. 但是我对它的印象竟然只有这个名字本身了 Orz. 对于这个算法本身倒是忘得一干二净. 于是我打算系统性地学习一下这个算法的原理, 并将它总结出来写成这篇博客. 不知道在哪里看到的一句话 :
Write a function that prunes a
Tree
t
mutatively.t
and its branches always have zero or two branches. For the trees with two branches, reduce the number of branches from two to one by keeping the branch that has the smaller label value. Do nothing with trees with zero branches.Prune the tree in a direction of your choosing (top down or bottom up). The result should be a linear tree.