string conversion; for(intj = 0; j < numRows && j < s.size(); j++) conversion = conversion + result[j]; returnconversion; } }; 提交代码后,42ms,击败15%。我想不出更好的解法了。看看大佬的,mmp,也没看懂。 classSolution {public:stringconvert(strings,intnumRows) { vector<string>substring...
class Solution { public: string convert(string s, int numRows) { if (numRows == 1) return s; vector<string> rows(min(numRows, int(s.size())); int curRow = 0; bool goingDown = false; for (char c : s) { rows[curRow] += c; if (curRow == 0 || curRow...
思路1:将Z字形字符数组存储到一个字符数组中,然后按行读取字符。 思路2:直接根据规律计算。 代码1: classSolution {public:stringconvert(strings,intnumRows) {intlen_s=s.size();if(numRows==1)returns;intnumCols=(numRows-1)*len_s/(numRows*2-2)+numRows-1;charres[numRows][numCols];for(inti=...
好了,正式开始撸代码 class Solution { public: string convert(string s, int numRows) { vector<string> vecRowStrings(numRows); int iRow = 0; bool bIsAdd = true; for (auto c : s) { auto sRowString = vecRowStrings[iRow]; sRowString += c; if (0 == iRow) { bIsAdd = true; }...
Can you solve this real interview question? Zigzag Conversion - 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
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 = 3Output:"PAHNAPLSIIGYIR" Example 2: Input:s = "PAYPALISHIRING", numRows = 4Output:"PINALSIGYAHRPI"Expl...
leetcode 6. ZigZag Conversion 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...
Leetcode: ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows likethis: (you may want to displaythispattern in a fixed fontforbetter legibility) P A H N A P L S I I G Y I R...
LeetCode笔记:6. ZigZag Conversion 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: "PAHNAP...
[LeetCode题解] ZigZag Conversion 原文在这,可以来我blog翻翻哦。 第二天。今天AC掉了一道之前没AC掉的题目。。。 今天的题目是6. ZigZag Conversion 题目描述: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern...