leetcode problem 6: zigzag word
Posted nosaferyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode problem 6: zigzag word相关的知识,希望对你有一定的参考价值。
class Solution { public: string convert(string s, int numRows) { if (numRows == 1){ return s; } string out; for (int i = 0; i < numRows; ++i){ int j = 0; while (true){ int pos = -1; if (j % 2 == 0){ pos = j * (numRows - 1) + i; } else if (i != 0 && i != numRows - 1) { pos = j * (numRows - 1) + numRows - i - 1; } if (pos >= (int)s.length()){ break; } if (pos >= 0){ out.append(1, s[pos]); } j ++; } } return out; } };
以上是关于leetcode problem 6: zigzag word的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode&Python] Problem 867. Transpose Matrix
#Leetcode# 6. ZigZag Conversion
[LeetCode&Python] Problem 628. Maximum Product of Three Numbers
[LeetCode&Python] Problem 783. Minimum Distance Between BST Nodes