Vim 宏: 录制、修改与执行
引言
在我学习 Vim 的过程中,最具有启发意义的一句话是:
Vim 其实是一门“编程语言”
How to use the semantic actions to generate the symbol tables in ANTLR4
摩尔投票法
引言
今天又做到了 Leetcode 169. 多数元素 这一道题. 我依稀记得最优的解法叫做什么摩尔投票法. 但是我对它的印象竟然只有这个名字本身了 Orz. 对于这个算法本身倒是忘得一干二净. 于是我打算系统性地学习一下这个算法的原理, 并将它总结出来写成这篇博客. 不知道在哪里看到的一句话 :
CS61A 的项目三之 Ants vs SomeBees 实现 (2021-Fall)
Lab14 题解 (UCB CS61A@2021 Fall)
Trees
Q1: Prune Min
Write a function that prunes a
Treetmutatively.tand 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.
Hw10 题解 (UCB CS61A@2021 Fall)
BNF
Q1: Grouping and Pipes
In this question, you will add support for grouping and piping.
Recall that grouping allows for an entire regular expression to be treated as a single unit, and piping allows for a pattern to match an expression on either side. Combined, these will let us create patterns which match multiple strings!
Define the
groupandpipeexpressions in your grammar.
- A
groupconsists of anyregexexpression surrounded by parentheses (()).- A
pipeoperator consists of aregexexpression, followed by a pipe (|) character, and lastly followed by anotherregexexpression.For example,
r"apples"would match exactly the phrase “apples” in an input. If we wanted our pattern from before to match “oranges” as well, we could expand ourrstringto do so using groupings and pipes:r"(apples)|(oranges)".