博客
关于我
Z 字形变换
阅读量:723 次
发布时间:2019-03-21

本文共 1187 字,大约阅读时间需要 3 分钟。

var convert = function (s, numRows) {    //numRows行    if (numRows < 2) {        return s    }    const mid = numRows - 2 //中间列    const len = s.length    //求列    if (len < 2) {        return s    }    let count = Math.floor(len / (numRows + mid)) * (mid + 1)    // console.log(count, 'count');    const tmp = len % (numRows + mid)    // console.log(tmp, 'tmp');    if (tmp < numRows) {        count = count + 1    } else {        count = count + 1 + (tmp - numRows)    }    console.log(count);    //生成二维数组 numRows行 count列    const store = new Array(numRows).fill('').map(() => {        return new Array(count).fill('')    })    let j = 0, k = 0, flag = true    for (let i = 0; i < len; i++) {        if (j === numRows) {            flag = false            j = j - 2            k++        }        if (j === 0) {            flag = true        }        if (flag) {            store[j][k] = s[i]            j++        } else {            store[j][k] = s[i]            j--            k++        }    }    const result = []    for (const e of store) {        for (const f of e) {            if (f !== '') {                result.push(f)            }        }    }    return result.join('')};

 

转载地址:http://gmirz.baihongyu.com/

你可能感兴趣的文章
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>