• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            將一個之字形排列的字符串按行輸出,e.g.,

            P    A   H    N
            A P L S I  I G
            Y    I    R

            Input: s = "PAYPALISHIRING", numRows = 3
            Output: "PAHNAPLSIIGYIR"

            直接模擬即可,python寫得比較爛


            C++版:


             1 #6
             2 #Runtime: 88 ms (Beats 13.2%)
             3 
             4 class Solution {
             5 public:
             6     string convert(string s, int nRows) {
             7         if(nRows == 1) return s;
             8         string res;
             9         int i = 0, j = 0, n = s.length();
            10         while(j < s.length()) {
            11             res.push_back(s[j]);
            12             j += 2 * nRows - 2;
            13         }
            14         for(i = 1; i < nRows - 1; ++i) {
            15             j = i;
            16             while(j < s.length()) {
            17                 res.push_back(s[j]);
            18                 j += 2 * nRows - 2 * (i + 1);
            19                 if(j < s.length()) {
            20                     res.push_back(s[j]);
            21                     j += 2 * i;
            22                 }
            23             }
            24         }
            25         j = nRows - 1;
            26         while(j < s.length()) {
            27             res.push_back(s[j]);
            28             j += 2 * nRows - 2;
            29         }
            30         return res;
            31     }
            32 };



            Python版:


             1 #6
             2 #Runtime: 1107 ms (Beats 10.51%)
             3 #Memory: 21.3 MB (Beats 5.28%)
             4 
             5 class Solution(object):
             6     def convert(self, s, numRows):
             7         """
             8         :type s: str
             9         :type numRows: int
            10         :rtype: str
            11         """
            12         if numRows == 1:
            13             return s
            14         col, i = 0, 0
            15         ans = []
            16         while i < len(s):
            17             if col % (numRows - 1) == 0:
            18                 t = []
            19                 for j in range(numRows):
            20                     if i >= len(s):
            21                         t.append(' ')
            22                     else:
            23                         t.append(s[i])
            24                         i += 1
            25             else:
            26                 t= []
            27                 for j in range(numRows - 1, -1, -1):
            28                     if j % (numRows - 1) == col % (numRows - 1):
            29                         t.append(s[i])
            30                         i += 1
            31                     else:
            32                         t.append(' ')
            33             ans.append(t)
            34             col += 1
            35         ans = list(map(list, zip(*ans)))
            36         ans = [i for item in ans for i in item]
            37         ans = ''.join(ans)
            38         return ans.replace(' ''')
            久久亚洲日韩看片无码| 久久无码AV中文出轨人妻| 99久久无码一区人妻a黑| 青青青伊人色综合久久| 久久午夜夜伦鲁鲁片免费无码影视 | 天天爽天天爽天天片a久久网| 无夜精品久久久久久| 久久99精品久久久久久| 日韩人妻无码一区二区三区久久99| 久久99久久99精品免视看动漫| 亚洲欧美精品一区久久中文字幕| 欧美久久综合性欧美| 色偷偷久久一区二区三区| 四虎国产精品免费久久| 国产精品gz久久久| 色综合久久久久| 国产成人久久激情91| 亚洲成色www久久网站夜月| 伊人久久大香线蕉精品不卡| 久久毛片免费看一区二区三区| 日韩精品国产自在久久现线拍| 国产精品无码久久综合| 奇米影视7777久久精品| 国产成人精品综合久久久| 香蕉久久夜色精品国产2020 | 亚洲国产精品久久电影欧美| 久久精品国产亚洲av瑜伽| 久久精品国产99国产电影网| 亚洲AV无码久久精品成人| 久久亚洲AV成人无码| 狠狠综合久久综合88亚洲| 久久婷婷是五月综合色狠狠| 久久综合鬼色88久久精品综合自在自线噜噜 | 久久精品亚洲中文字幕无码麻豆| 亚洲午夜无码AV毛片久久| 怡红院日本一道日本久久| 91精品久久久久久无码| 久久久久亚洲精品无码网址| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 99久久er这里只有精品18| 久久精品人人做人人妻人人玩|