[RATS]week-4

Algorithm

Question

将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。
比如输入字符串为 “LEETCODEISHIRING” 行数为 3 时,排列如下:
L C I R
E T O E S I I G
E D H N
之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:“LCIRETOESIIGEDHN”。
请你实现这个将字符串进行指定行数变换的函数:
string convert(string s, int numRows);
示例 1:
输入: s = “LEETCODEISHIRING”, numRows = 3
输出: “LCIRETOESIIGEDHN”
示例 2:
输入: s = “LEETCODEISHIRING”, numRows = 4
输出: “LDREOEIIECIHNTSG”
解释:
L D R
E O E I I
E C I H N
T S G
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/zigzag-conversion
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

Answer

   String[] strArray = s.split("");
        List<StringBuilder> zList = new ArrayList<>();
        boolean isTop = false;
        for (int i = 0; i < strArray.length && i < numRows; i++) {
            zList.add(new StringBuilder(strArray[i]));
        }
        int slantIndex = 2, vIndex = 1;
        for (int i = numRows; i < strArray.length; i++) {
            if (isTop) {
                if (vIndex < numRows - 1) {
                    zList.get(vIndex++).append(strArray[i]);
                } else {
                    zList.get(zList.size() - 1).append(strArray[i]);
                    isTop = false;
                    vIndex = 1;
                }
            } else {
                int tmpIndex = zList.size() - slantIndex++;
                if (tmpIndex > 0) {
                    zList.get(tmpIndex).append(strArray[i]);
                } else {
                    zList.get(0).append(strArray[i]);
                    slantIndex = 2;
                    isTop = true;
                }
            }
        }
        StringBuilder sbResult = new StringBuilder();
        for (StringBuilder sb : zList) {
            sbResult.append(sb);
        }
        return sbResult.toString();

官方思路

控制上下游标,到顶则++,到底则–

Result

在这里插入图片描述

Review

Spring Cloud - Main Projects

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.

Spring CLoud Config 为分布式系统中的外部化的配置文件提供服务器端和客户端的支持。通过配置服务器你有一个集中的地方跨环境的管理应用程序的外部属性。这个该讲同时在客户端和服务端相等的适配Spring环境和抽象属性源,他们不经非常好的适应Spring Application,而且也能被应用在各种语言中各种应用。当通过部署开发环境到测试环境的管线再到生产环境,你可以在这些环境中管理配置文件,并且确定做环境迁移的时候,应用程序拥有运行所需要的一切。这些服务后台存储的默认实现使用git很容易支持打上环境配置的版本标签,也可以访问各种各样的工具来管理内容。添加可替代实现并使用Spring Configuration很轻松的将他们插入其中。

Features
Spring Cloud Config Server features:
HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)
Encrypt and decrypt property values (symmetric or asymmetric)
Embeddable easily in a Spring Boot application using @EnableConfigServer
Config Client features (for Spring applications):
Bind to the Config Server and initialize Spring Environment with remote property sources
Encrypt and decrypt property values (symmetric or asymmetric)

特性
Spring Cloud Config 服务特性:
Http ,resource-based API针对外部配置文件(name-value对或等价的YAML文件)。
加密和解密属性值(对称和非对称)
使用@EnableConfigServer可以很容易的嵌入一个SpringBoot应用
配置客户端特性(针对Spring Application):
绑定到配置服务并通过远程属性源初始化Spring环境。
加密和解密属性值(对称和非对称)

Getting Started
As long as Spring Boot Actuator and Spring Config Client are on the classpath any Spring Boot application will try to contact a config server on http://localhost:8888, the default value of spring.cloud.config.uri. If you would like to change this default, you can set spring.cloud.config.uri in bootstrap.[yml | properties] or via system properties or environment variables.

只要是Spring Boot 执行器和Spring Config 客户端在类路径下的任何Spring Boot 应用,就可以尝试去关联一个在Http://localhost:8888, 这个默认值是spring.cloud.config.uri。如果想要修改这个默认值,可以通过设置应道程序的spring.cloud.config.uri(yml或 属性文件)或者通过系统属性或环境变量。

@Configuration
@EnableAutoConfiguration
@RestController
public class Application {

  @Value("${config.name}")
  String name = "World";

  @RequestMapping("/")
  public String home() {
    return "Hello " + name;
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}

The value of config.name in the sample (or any other values you bind to in the normal Spring Boot way) can come from local configuration or from the remote Config Server. The Config Server will take precedence by default. To see this look at the /env endpoint in the application and see the configServer property sources.
To run your own server use the spring-cloud-config-server dependency and @EnableConfigServer. If you set spring.config.name=configserver the app will run on port 8888 and serve data from a sample repository. You need a spring.cloud.config.server.git.uri to locate the configuration data for your own needs (by default it is the location of a git repository, and can be a local file:… URL).

**
例子中config.name的值(或任何其他值你绑定到常规的SpringBoot)可以来自本地配置文件或者远程配置服务。远程配置服务将默认优先。去看这个look在应用程序的/env下的终结点并且看配置服务的属性源。
为了运行你自己的服务使用spring-cloud-config-server依赖和@EnableConfigServer.如果你设置spring.config.name=configserver,应用程序会运行在8888端口并且使用来自示例仓库的服务数据。为了自己的需求你需要spring.cloud.config.server.git.uri来定位服配置数据(默认的位置是git仓库,也可以是一个本地file)
**

Tips - MySQL 索引1

索引模型:
1.哈希表
Key-value存储数据结构。用一个哈希函数吧key换算成确定的位置上,然后把value放在数组的这个为主。
注意,不同的key经过Hash函数计算会得到同一个值。针对此问题的解决方案,是构建一个链表。
该算法适用于内存数据库及Redis等NoSQL的数据库引擎。
2.有序数组
在等值查询和范围查询场景中的性能就都非常好。但插入操作性能非常差。所以适合静态数据引擎。
3.搜索树
包含2叉树和N叉树(InnoDB)
4.跳表
5.LSM数

InnoDB 中
1.使用B+树(N叉树)的数据结构存储数据,将整棵树的高度位置在很小的范围内。
2.没有主键的表,innodb会默认创建一个RowID作为主键
3.B+树的插入可能会引起数据页的分裂,删除可能会引起数据页的合并,二者都是比较重的IO消耗,所以比较好的方式是顺序插入数据,这也是我们一般使用自增主键的原因之一。
4.在Key-Value的场景下,只有一个索引且是唯一索引,则适合直接使用业务字段作为主键索引。
5.新增数据时,数据是追加的,不会产生叶子节点的分离
6.因为二级索引存放的是主键索引的值,所以主键长度越短所占空间越小4
7.索引类型:
主键索引(聚簇索引):节点存储主键和数据
非主键索引(二级索引):存储非主键索引数据和主键值。
8.使用自增作为主键:append方式追加数据。性能和空间更好
9.一个数据页满了,会新增一个数据页,叫做页分裂,导致性能下降。空间利用率降低大概50%。相邻的两个数据页利用率很低的时候,也做页数据页合并。
10.回表:非主键索引查找到主键,然后再到主键索引查找数据。
11.数据量非常大的时候,非主键索引查找速度大于主键索引。

以上自极客时间-《MySQL实战45讲》学习笔记

Share - 软件交付的演进历程 from InfoQ

软件交付的演进历程

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值