pseudocode of zigzag conversion
1.Title : The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P A H N A P L S I I G Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
2.pseudocode :
creat data structure:
the given number of rows → nRows;
the given text string → s;
stringBuffer[] to restore result → sb;
set char position index i = 0;row position index j = 0;combing outcome index k = 1;
while i < the length of s,then
for each j from 0 to (nRows - 1)
append the ith char of s to sb[j];
i++;
end
for each j from (nRows - 2) to 1
append the ith char of s to sb[j];
i++;
end
end
//form a united outcome
for each k from 1 to (nRows - 1)
append sb[k] to sb[0];
end
terminate and output sb[0];
pseudocode of zigzag conversion的更多相关文章
- 【leetcode❤python】 6. ZigZag Conversion
#-*- coding: UTF-8 -*- #ZigZag Conversion :之字型class Solution(object): def convert(self, s, numRow ...
- 64. ZigZag Conversion
ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...
- No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- leetcode第六题 ZigZag Conversion (java)
ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...
- leetcode题解 6.ZigZag Conversion
6.ZigZag Conversion 题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...
- 6.[leetcode] ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- 字符串按照Z旋转90度然后上下翻转的字形按行输出字符串--ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- LeetCode--No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- leetcode-algorithms-6 ZigZag Conversion
leetcode-algorithms-6 ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag ...
随机推荐
- my new start
my new start in blog csdn : today i formally migrate my personal technical blog from sina to here in ...
- 201521123091 《Java程序设计》第4周学习总结
Java 第二周总结 第四周的作业. 目录 1.本章学习总结 2.Java Q&A 3.使用码云管理Java代码 4.PTA实验 1.本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点 ...
- 团队作业4——第一次项目冲刺(Alpha版本)4th day
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 计时功能已经完成,然后24点的代码如何在游戏界面与界面组件联系上正在进行. 四.困难与问题 1.在安卓框架与java代码的结合 ...
- 201521123101 《Java程序设计》第6周学习总结
1. 本周学习总结 1.面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 1.clone方法 1.1 Object对象中 ...
- [转载] sublime text 2 调试python时结果空白
之前用的时候都一切正常,今天突然就出现了这个问题.按ctrl+b执行的时候结果只有空白,查了很多文章都只提到了中文路径.系统路径等等,没有解决问题,直到看到了这篇文章:http://384444165 ...
- JSP学习(一)之中文乱码问题的解决
一.响应中的乱码 我们所看到的页面,是由服务器把内容放入响应(response)中,然后发送给浏览器的.如果响应中的数据无法被正常解析,就会出现中文乱码.为什么英文不存在乱码问题?因为无论是ISO-8 ...
- 框架应用:Spring framework (五) - Spring MVC技术
软件开发中的MVC设计模式 软件开发的目标是减小耦合,让模块之前关系清晰. MVC模式在软件开发中经常和ORM模式一起应用,主要作用是将(数据抽象,数据实体传输和前台数据展示)分层,这样前台,后台,数 ...
- 泛型在Web中的作用
当我们写网页的时候,常常会有多个DAO,我们要写每次都要写好几个DAO,这样会有点麻烦. 那么我们想要的效果是什么呢??只写一个抽象DAO,别的DAO只要继承该抽象DAO,就有对应的方法了. 要实现这 ...
- Java main方法继承
java中main方法是可以继承的 Test1.java package Variables; public class Test1 { public static void main(String[ ...
- JDBC操作数据库之查询数据
以数据库中查找图书信息,并将信息显示在jsp页面当中为例,下面贴上代码片段: (1)在index.jsp页面代码body中只要添加如下一段代码: <a href="FindServle ...