基操
1 | import json |
1 | import json |
特性: 这个断言是从右边开始匹配
1 | e.g.01 |
特性: 这个断言是从右边开始匹配
1 | e.g.01 |
特性: 这个断言是从左边开始匹配
1 | e.g.01 |
特性: 这个断言是从左边开始匹配
1 | e.g.01 |
采用分治(Divide and Conquer)的思想,解题思路如下:
时间复杂度 O(nlogn)
1 | import java.util.Arrays; |
阿里云购买云服务,本地通过终端连接使用,终端工具,弹幕各种推荐 Mobaxtream, 打算试用一下
阿里云上创建实例后,你只能通过他们提供的终端工具访问,如果你想要通过其他终端工具访问服务器,需要设置安全组。这个安全组你可以理解为云服务形势下的开启防火墙端口。
常用端口:
安全组 -> 创建安全组,将常用端口添加进去即可
实例可以理解为远程虚拟机,进入阿里云主界面,顶部选择 控制台 -> 点右上角三条杠 -> 下拉单选择 实例 -> 右上角选择 创建实例
自定义购买下面选择:
其他只需要注意一下安全组设置即可,创建完毕后,点击你创建的实例,进入面板后就可以看到你创建的实例的公网 IP,然后点击右上角的全部操作下拉单 -> 修改密码
下载 Mobaxtream 并安装,没什么好说的,新建 session 然后填写账号密码尝试链接,没什么问题的话都 OK 的
1 | yum update |
控制台界面搜索 容器镜像服务 -> 镜像工具 -> 镜像加速器
他会根据账号给出加速地址和配置方法,很直观, 对于 CentOS 可以通过修改 daemon 配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://xxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
1 | docker run -d -p 8080:80 --name my-nginx nginx |
PS: 第一次测试内部访问成功,外部失败,查看安全组,发现添加输入框末端需要点击保存…
文件名规范
-
链接, 这时 hexo
命令自己的规范, 如果我用命令 hexo n 'my new post'
它会自动把文件命名为 ‘my-new-post’内容规范
,
替换 , [\s]*
, 句号同理PS: 有兴趣的话可以做一个 VS 插件玩玩
插件注意点:
\. $
-> .
遇到一个问题,在写测试的时候需要产生一串随机数,找了一下解决方案,记录一下
需求:
1 | public class RandomDemo { |
%04d 的含义:
算法描述
1 | public class SelectionSortDemo { |
算法描述
操作没问题,但是你难道不觉得,这个比较中间过程中的交换过程很浪费资源吗?为了省去中间的交换过程,我们有了选择排序。
时间复杂度:O(n2)
1 | /** |
插入排序是一个很基础的排序方法,基本解法思路为:
将待排序序列第一个元素看做一个有序序列,把第二个元素到最后一个元素当成是未排序序列。从头到尾依次扫描未排序序列,将扫描到的每个元素插入有序序列的适当位置。(如果待插入的元素与有序序列中的某个元素相等,则将待插入元素插入到相等元素的后面。)
时间复杂度:O(n2)
1 | /** |
The Composite Pattern allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
组合模式让我们可以将数据组合成树状结构。他可以让我们以统一的模式对待单个节点或整个组合体
书接上一个 Iterator 章节,现在 DinerMenu 业务扩展了,我们想要在 DinerMenu 的基础上再增加一个子目录来打印一个点心子菜单。现在已有的代码结构并不能完成我们的需求,我们将使用 组合模式 重构我们的代码。
更具上面这个需求我们可以将需要展示的结构抽象为如下结构
1 | +------------+ |
我们要实现用统一的接口访问 Menu 和 MenuItem,所以不难想到,我们需要在这两个概念外面包装一个统一的对外接口。
代码实现如下:
1 | // 我们抽象一个组合节点和叶子结点公用的超集节点,叫做 MenuComponent, 他包含了这两种节点都要用到的方法,虽然这样做会有点冗余 |
上面这种 print 用了内部 Iterator 的方法,简单了很多, 那么如何实现一个外部的 Iterator 呢
我们先为基类添加 createIterator 方法
1 | public class MenuComponent { |
然后声明一个 Composite 的 Iterator 的具体实现类, 并让 Composite 实现类返回它
CompositeIterator 说明:
这个 Iterator 说实话不是很容易看懂。我们最好结合下面的 printVegetarianMenu() 方法的使用情况一起来看。由下面的方法调用,我们可以反推出这个 Iterator 实现类的作用。
每次调用 hasNext() 时,CompositeIterator 会返回一个 MenuCompoment 类型的对象。有可能是 Menu, 也有可能是 MenuItem。
而且就算返回的是 Menu, 他之后还是会把这个 Menu 的 MenuItem 在下一次返回。由此我们可以推测出,在 next() 反 Menu 之后,还有一个隐式的将 Menu 子节点 push 到 stack 中的动作。
PS: 这段代码的关键点是,stack 中存储的是 Iterator 对象。当这个对象里面没有值的时候,需要做 pop 操作弹出 it, 这里有点绕
1 | public class CompositeIterator implements Iterator<MenuComponent> { |
由于叶子节点是不需要迭代的,我们返回一个空的 iterator, 每次调用 hasNext() 都返回 false
1 | public class NullIterator implements Iterator { |
测试代码
1 | public class Client { |
上面用的是外部 Iterator 的方式,需要自己控制当前节点位置,所以实现上比内部的那种要复杂很多。
图示说明:
1 | +----------------+ |