博客
关于我
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/

你可能感兴趣的文章
mysql备份与恢复
查看>>
mysql备份工具xtrabackup
查看>>
MySQL外键约束
查看>>
MySQL多表关联on和where速度对比实测谁更快
查看>>
mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
查看>>
mysql如何做到存在就更新不存就插入_MySQL 索引及优化实战(二)
查看>>
MySQL如何实现ACID ?
查看>>
mysql如何记录数据库响应时间
查看>>
Mysql字段、索引操作
查看>>
MySQL字符集与排序规则
查看>>
mysql存储中文 但是读取乱码_mysql存储中文乱码
查看>>
mysql存储登录_php调用mysql存储过程会员登录验证实例分析
查看>>
MySql存储过程中limit传参
查看>>
MySQL存储过程入门
查看>>
mysql存储过程批量建表
查看>>
mysql存储过程详解
查看>>
MySQL学习-group by和having
查看>>
MySQL学习-MySQL条件查询
查看>>
MySQL学习-SQL语句的分类与MySQL简单查询
查看>>
MySQL学习-子查询及limit分页
查看>>