LeetCode刷题之旅(6)
来源:互联网 发布:windows驱动器被锁定 编辑:程序博客网 时间:2024/05/18 15:04
把握计数变量的循环即可,解决代码如下:
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)
- 【BZOJ2660】[Beijing wc2012]最多的方案【找规律】【计数DP】【二进制】【Fibonacci】
- 颜色代码大全
- 常用排序算法总结(五)
- sqlite基本sql语句使用
- Servlet路径跳转问题
- LeetCode刷题之旅(6)
- 有趣的通讯录—<静态版>
- 求最长等差数列长度
- Scheme
- Android学习笔记之AndroidManifest.xml文件解析
- 解决RecyclerView上拉加载、下拉刷新、Header和Footer的第三方解决方案
- c++ 内存申请释放,构造函数,析构函数,执行顺序
- Generate Parentheses
- Android分包(MultiDex)后编译加速方案