lc6 ZigZag Conversion

分成两步,

第一步垂直向下,

1

1

1

1

第二步倾斜向上

1      1 

1    1

1  1

1

用nRows个StringBuilder 然后将他们合并即可

 class Solution {
public String convert(String s, int numRows) {
if(s.length() < numRows)
return s;
if(numRows < 2)
return s;
String[] res = new String[numRows];
for(int i=0; i<numRows; i++){
res[i] = Character.toString(s.charAt(i));
} for(int i=numRows; i<s.length(); i++){
int tmp = i % (2*numRows - 2);
if(tmp >= 0 && tmp < numRows){
res[tmp] += (s.charAt(i));
}else{
res[numRows-tmp%(numRows-1)-1] += (s.charAt(i));
}
}
StringBuilder sb = new StringBuilder();
for(String i : res)
sb.append(i);
return sb.toString(); }
}

lc6 ZigZag Conversion的更多相关文章

  1. 【leetcode❤python】 6. ZigZag Conversion

    #-*- coding: UTF-8 -*- #ZigZag Conversion :之字型class Solution(object):    def convert(self, s, numRow ...

  2. 64. ZigZag Conversion

    ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...

  3. No.006 ZigZag Conversion

    6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...

  4. leetcode第六题 ZigZag Conversion (java)

    ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...

  5. leetcode题解 6.ZigZag Conversion

    6.ZigZag Conversion 题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...

  6. 6.[leetcode] ZigZag Conversion

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  7. 字符串按照Z旋转90度然后上下翻转的字形按行输出字符串--ZigZag Conversion

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  8. LeetCode--No.006 ZigZag Conversion

    6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...

  9. leetcode-algorithms-6 ZigZag Conversion

    leetcode-algorithms-6 ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag ...

随机推荐

  1. day15 python-03 列表,元组,字典

    Python之路,Day3 = Python基础3 注: extend: 拼接 enumerate:打印序号,返回两个值 模块的简单使用 sys模块 #!/usr/bin/env python #这句 ...

  2. MAMP mysql无法启动 总结(以后有发现再添加)

    1.错误信息Can't start server : Bind on unix socket: Address already in use 解析:主要原因是上次关闭Mysql是出现异常而导致的, 解 ...

  3. 关于Unity中脚本

    脚本编译: Unity可以把脚本编译为DLL,DLL将在运行时编译运行.这样可以提高执行 的速度,比传统的JavaScritp快20倍. 脚本具体的编译需要以下4步. 1: 所有的"Stan ...

  4. F - GCD - Extreme (II) UVA - 11426

    Given the value of N, you will have to find the value of G. The definition of G is given below:

  5. webjars和springboot热启动

    webjars WebJars将Web前端Javascript和CSS等资源打包成Java的Jar包, 以便能使Maven的依赖管理支持静态JavaScript库/CSS库,比如jQuery.layu ...

  6. USACO 2009 Open Treasure Cave /// DFS||并查集 oj26215

    题目大意: 输入 p,n,t :p为地点数 判断 t 能否回到源点1 接下来n行 每行输入 a b c: a能到达b和c Sample Input 13 6 76 7 82 3 410 11 128 ...

  7. 记录openSUSE 源码安装node.js

    openSUSE版本: 42.2 目标:安装好 Node.js v6.10.3 在终端中可以使用 "su" 命令,切换到root用户. 1. 安装 gcc,gcc-c++ zypp ...

  8. Clover config.plist Boot部分

    <key>Boot</key> <dict> <key>Arguments</key> < nv_disable= kext-dev- ...

  9. AMPQ

    AMPQ AMQP,即Advanced Message Queuing Protocol,高级消息队列协议, 是`应用层协议的一个开放标准,为面向消息的中间件设计`. 由于AMQP是一个网络协议,所以 ...

  10. 菜鸟nginx源码剖析数据结构篇(十) 自旋锁ngx_spinlock[转]

    菜鸟nginx源码剖析数据结构篇(十) 自旋锁ngx_spinlock Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csd ...