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 ...
随机推荐
- 【深入Java虚拟机】之七:Javac编译与JIT编译
转载请注明出处:http://blog.csdn.net/ns_code/article/details/18009455 编译过程 不论是物理机还是虚拟机,大部分的程序代码从开始编译到最终转化成物理 ...
- 201521123053《Java课程设计》第七周学习总结
1. 本章学习总结 2. 书面作业 Q1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:代码如下 public boolean contains(Objec ...
- 201521123113 《Java程序设计》第1周学习总结
1. 本章学习总结 1.java是一个面向对象的编程语言,相对于c++来说代码较简便又好用.第一次接触java时感觉每句代码比较难写,但学习了一些快捷方法后就很方便了. 2.java运行于JVM,因此 ...
- java 课程设计 购物车系统 个人
Q1.团队课程设计博客链接 团队博客 Q2.个人负责模块或任务说明 我主要负责main函数的编写和系统中瞎看功能代码的编写. Q3.自己的代码提交记录截图 main函数代码如下: public sta ...
- JavaScript总体的介绍【JavaScript介绍、定义函数方式、对象类型、变量类型】
什么是JavaScript? 我们可以从几个方面去说JavaScript是什么: 基于对象 javaScript中内置了许多对象供我们使用[String.Date.Array]等等 javaScrip ...
- springmvc02
1,创建实体类对象User 注意要导入 bean-validator.jar 包 package com.yangw.springmvc.entity; import org.hibernate.va ...
- 鸟哥Linux学习笔记05
1, 文件系统通常会将 权限与属性放置到inode中,至于实际数据则放置到data block块中.另外还有一个超级块(superblock)会记录整个文件系统的整体内容,包括ino ...
- angular directive知识
一般来讲 directive名字遵循一下规则: 1.忽略以x-和data-为元素/属性的前缀 2.转化“:”,“-”,“_”命名为驼峰命名 如下所示 <div ng-controller=&qu ...
- PHP实现页面静态化
1.通过buffer来实现 需要用file_put_contents ob_get_clean()等内置函数 ob_start (); include "filterpost.htm ...
- angularjs——路由篇
路由 路由功能是由 routeProvider服务 和 ng-view 搭配实现,ng-view相当于提供了页面模板的挂载点,当切换URL进行跳转时,不同的页面模板会放在ng-view所在的位置; 然 ...