LeetCode刷题之旅(6)
来源:互联网 发布:阿里云素材库 编辑:程序博客网 时间:2024/05/04 16:37
把握计数变量的循环即可,解决代码如下:
public class Solution { public String convert(String s, int numRows) { if (numRows == 1 || s.length() <= 1) { return s; } String[] strings = new String[numRows]; for (int i = 0; i < numRows; i++) { strings[i] = ""; } int n = s.length(); int j = 0; String result = ""; boolean add = true; for (int i = 0; i < n; i++) { strings[j] += s.charAt(i); if (j == numRows - 1) { add = false; } if (add) { j++; }else{ j--; } if (j == 0 && !add) { add = true; } } for (String string : strings) { result += string; System.out.println(string); } return result; }}
0 0
- LeetCode刷题之旅(6)
- LeetCode刷题之旅(6)
- LeetCode刷题之旅(1)
- LeetCode刷题之旅(2)
- LeetCode刷题之旅(3)
- LeetCode刷题之旅(4)
- LeetCode刷题之旅(5)
- LeetCode刷题之旅(7)
- LeetCode刷题之旅(5)
- LeetCode刷题之旅(7)
- LeetCode刷题之旅(8)
- LeetCode刷题之旅(9)
- LeetCode 刷题之旅
- LeetCode之旅(6)
- leetcode之旅(6)-Add Digits
- Leetcode 刷题之哈希表
- LeetCode之旅(2)
- LeetCode之旅(3)
- HDU 1017 A Mathematical Curiosity【水题】
- Zen Coding的一种快速编写HTML/CSS代码的方法
- 交换两个变量值的五种方法及相关解析
- JVM——Java虚拟机架构
- ACM第三期1014
- LeetCode刷题之旅(6)
- 街区最短路径问题
- 模拟结婚和离婚
- Windows如何开启telnet服务
- 安卓Drawable 小技巧以及建议收录1.
- 一点实例明白mysql数据库存储过程
- C语言实现二叉树的递归遍历与非递归遍历
- 廉价DSO Hantek 6022BL说明书上没有的内容
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp