Skip to content

Latest commit

 

History

History
137 lines (104 loc) · 4.5 KB

ARTS06-0811.md

File metadata and controls

137 lines (104 loc) · 4.5 KB

ARTS06-20180811

Algorithm

6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R

And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);

Example 1:

Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"

Example 2:

Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:

P     I    N
A   L S  I G
Y A   H R
P     I
package org.nocoder.leetcode.solution;

/**
 * 6. ZigZag Conversion
 *
 * The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
 *
 * P   A   H   N
 * A P L S I I G
 * Y   I   R
 * And then read line by line: "PAHNAPLSIIGYIR"
 *
 * Write the code that will take a string and make this conversion given a number of rows:
 *
 * string convert(string s, int numRows);
 * Example 1:
 *
 * Input: s = "PAYPALISHIRING", numRows = 3
 * Output: "PAHNAPLSIIGYIR"
 * Example 2:
 *
 * Input: s = "PAYPALISHIRING", numRows = 4
 * Output: "PINALSIGYAHRPI"
 * Explanation:
 *
 * P     I    N
 * A   L S  I G
 * Y A   H R
 * P     I
 *
 * @author jason
 * @date 18/8/12.
 */
public class ZigZagConversion {

    public String convert(String s, int nRows) {
        if (s == null || s.length() == 0 || nRows <= 1) {
            return s;
        }

        StringBuilder res = new StringBuilder();
        int size = 2 * nRows - 2;
        for (int i = 0; i < nRows; i++) {
            for (int j = i; j < s.length(); j += size) {
                res.append(s.charAt(j));
                if (i != 0 && i != nRows - 1) {
                    int temp = j + size - 2 * i;
                    if (temp < s.length()) {
                        res.append(s.charAt(temp));
                    }
                }
            }
        }
        return res.toString();
    }
}

Review

google chrome now labels http sites as 'not secure'

https://www.wired.com/story/google-chrome-https-not-secure-label/

两年前,谷歌实现了一个承诺,chrome浏览器在未加密的网站前面贴上警告标志,来标识非https网站为不安全网站。

但是居然还有骂声,“他们只是科技行业,网络比科技行业大得多,这就是傲慢。“来自Dave Winer,他是RSS的创造者之一。

Let's Encrypt 提供了支持HTTPS连接的免费证书,并且已加密超过1.13亿个网站。

Tip

Docker 容器多目录挂载

项目的配置文件,日志,以及要写入的文件,不要直接写在docker container 内部,因为一旦镜像更新要运行新的容器或者容器被删除,那么容器写入到内部的文件内容会丢失,所以这些需要挂载到宿主机上以保证数据的持久化。

目录挂载的使用非常容易,只需要遭docker run 命令后跟 -v 参数加上<宿主机目录路径>:<容器内目录路径>即可, 多个目录的挂载就使用 多个 -v 参数加上<宿主机目录路径>:<容器内目录路径>

docker run -it -p 8080:8080 -v /Users/jason/my-service/config/:/usr/local/my-service/config/ -v  /Users/jason/my-service/log:/usr/local/my-service/log 192.168.28.121:9090/my-service:1.0

使用docker-compose的话在docker-compose.yml中增加volumes: - "/source:/destination"即可。

Share

分享一下我们现在的负载流程,使用阿里负载均衡加nginx代理转发

项目是采用DDD设计理念,前后端分离,前端使用vue.js,后端是基于springboot的多模块项目,大体分为web层和core层,web层负责处理客户端请求,core层包括domain和repository。每个项目使用两台server来运行docker化的web和core,也就是说运行了两个web,两个core。注册中心使用eureka。 接下来描述一下负载均衡配合nginx代理转发的工作流程: 首先请求会到负载均衡服务器,然后到nginx8080端口,如果是静态资源,则proxy_pass 到CDN,CDN回源到nginx80端口的web-front目录下,初次访问的时候从这里获取资源,缓存到CDN以加速客户端访问;如果是接口,则到对应的web层,然后到core层。