public class Solution {
public String convert(String s, int nRows) {
if (s == null || s.isEmpty() || s.length() <= nRows || nRows == 1) {
return s;
} int length = s.length(); StringBuilder sb = new StringBuilder(); int step = 2 * (nRows - 1);
int count = 0; for (int i = 0; i < nRows; i++){
int interval = step - 2 * i; for (int j = i; j < length; j += step){
sb.append(s.charAt(j));
count++;
if (interval > 0 && interval < step && j + interval < length && count < length) {
sb.append(s.charAt(j + interval));
count++;
}
}
}
return sb.toString();
}
}

最新文章

  1. 推荐13款javascript模板引擎
  2. iOS 跳转至AppStore评分页面
  3. (二)catalina.bat
  4. 如何使用 EXCEL 的筛选功能
  5. iOS中的几种定时器详解
  6. 关于ODI agent的配置部署
  7. 怎么动态生成js变量
  8. CSS中的opacity,不透明度的坑
  9. vue eventBus 跳坑的办法
  10. laravel的消息队列剖析
  11. Activiti6-数据库配置-dbconfig(学习笔记)
  12. Open Daylight integration with OpenStack: a tutorial
  13. 写个shell脚本依次运行每个程序半小时
  14. nodejs(二)浏览器与服务器连接初探
  15. 标准I/O流
  16. HTML编辑笔记1
  17. Double与BigDecimal 精度问题
  18. http协议基础(十)实体首部字段
  19. C#中的IDisposable模式
  20. YII2源码阅读:autoload_real.php 22~23行

热门文章

  1. 线段树Final版本
  2. js基础:关于Boolean() 与 if
  3. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
  4. Linux ssh 不需要输入密码的方法
  5. js获取集合对象的个数
  6. 在Altium Designer 2009下如何添加Logo图
  7. shell入门-sed-1
  8. 如何更新node和npm版本
  9. Math类简介
  10. ResultSetMetaData和ResultSet