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