• <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(' ''')
            久久精品视频91| 囯产极品美女高潮无套久久久 | 国产精品99久久免费观看| 一本久道久久综合狠狠躁AV| 中文字幕热久久久久久久| 精品国产VA久久久久久久冰 | 久久66热人妻偷产精品9| 久久精品免费观看| 亚洲精品成人久久久| 色诱久久久久综合网ywww| 久久久久久综合一区中文字幕 | 东方aⅴ免费观看久久av| 97超级碰碰碰久久久久| 无码人妻久久一区二区三区蜜桃| 97精品依人久久久大香线蕉97| 青青青青久久精品国产 | 成人久久免费网站| 99久久精品国产一区二区蜜芽| 久久免费看黄a级毛片| 国内精品久久久久久久coent| 久久夜色精品国产噜噜麻豆| 久久午夜福利电影| 青青草原综合久久大伊人精品| av色综合久久天堂av色综合在| 久久精品国产国产精品四凭| 久久免费视频观看| 狠狠88综合久久久久综合网| 久久久精品久久久久影院| 狠狠精品久久久无码中文字幕| 久久AV高清无码| 91精品国产9l久久久久| 久久午夜羞羞影院免费观看| 亚洲乱码精品久久久久..| 亚洲综合久久久| 亚洲国产成人久久一区久久| 久久久久九九精品影院| 久久精品国产亚洲av瑜伽| 久久久久综合中文字幕| 亚洲欧洲精品成人久久曰影片| 久久亚洲高清综合| 一本久久a久久精品综合香蕉|