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". 题目意思很简单,给定一个字符串以及行数之后输出一个按规...
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". 题解: 这道题就是看坐标的变化。并且需要分块处理。 n=2时,字符串坐标变成zigzag的走法就是: 02 4 6...
代码(Java): 代码语言:javascript 代码运行次数:0 AI代码解释 publicclassSolution{publicStringconvert(String s,int numRows){String[]row=newString[numRows];for(int k=0;k<numRows;k++)row[k]="";int i=0;int j=0;int gap=numRows-2;while(i<s.length()){for(j=0;j<numRows&&i<s.length(...
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 s, int numRows); Example 1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" Input: s = "PAYPALISHIRING...
LeetCode 6 ZigZag Conversion(Z型转换) 翻译 字符串“PAYPALISHIRING”通过一个给定的行数写成如下这种Z型模式:PAHNAPLSIIGYIR然后一行一行的读取:“PAHNAPLSIIGYIR” 写代码读入一个字符串并通过给定的行数做这个转换:stringconvert(stringtext,intnRows);调用convert("PAYPALISHIRING",3),应该返回"PAHNAPLSIIGY...
LeetCode ZigZag Conversion(将字符串排成z字型) 1 class Solution { 2 public: 3 string convert(string s, int nRows) { 4 string a=""; 5 int len=s.length(); 6 if(len<=nRows||nRows==1) return s; //只有n个,不足一个周期||排成一行...
ZigZagConversion The string"PAYPALISHIRING"is written in azigzagpattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... leetcode sed java i++ Java 转载 mb5fe55b6d43deb 2013-10-17 14:51:00 ...
Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" 思路: 遍历字符串,找出拐点,然后记录每一行的字母,最后把每一行字母拼接起来。
File metadata and controls Code Blame 63 lines (55 loc) · 1.58 KB Raw package tree; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * Created by pradhang on 7/11/2017. * Given a binary tree, return the zigzag level order traversal of its nodes...
LeetCode 6 (ZigZag Conversion) ZigZag Conversion(ZigZag转换) 1、题目描述: 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)...