• <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
            裸的最長公共子序列,復雜度O(mn)

             1 #1143
             2 #Runtime: 255 ms (Beats 94.79%)
             3 #Memory: 21.6 MB (Beats 79.65%)
             4 
             5 class Solution(object):
             6     def longestCommonSubsequence(self, text1, text2):
             7         """
             8         :type text1: str
             9         :type text2: str
            10         :rtype: int
            11         """
            12         dp = [[0] * (len(text2) + 1) for _ in range(len(text1) + 1)]
            13         for i in range(1, len(text1) + 1):
            14             for j in range(1, len(text2) + 1):
            15                 if text1[i - 1] == text2[j - 1]:
            16                     dp[i][j] = dp[i-1][j-1] + 1
            17                 else:
            18                     dp[i][j] = max(dp[i-1][j], dp[i][j - 1])
            19         return dp[len(text1)][len(text2)]


            只開兩個一維dp數組的版本:

             1 #1143
             2 #Runtime: 222 ms Beats 99.2%)
             3 #Memory: 13.6 MB (Beats 96.7%)
             4 
             5 class Solution(object):
             6     def longestCommonSubsequence(self, text1, text2):
             7         """
             8         :type text1: str
             9         :type text2: str
            10         :rtype: int
            11         """
            12         dp = [0] * (len(text2) + 1)
            13         dp_pre = [0] * (len(text2) + 1)
            14         for i in range(1, len(text1) + 1):
            15             for j in range(1, len(text2) + 1):
            16                 if text1[i - 1] == text2[j - 1]:
            17                     dp[j] = dp_pre[j-1] + 1
            18                 else:
            19                     dp[j] = max(dp_pre[j], dp[j - 1])
            20             dp_pre = dp
            21             dp = [0] * (len(text2) + 1)
            22         return dp_pre[len(text2)]

            999久久久免费精品国产| 久久不射电影网| 久久亚洲AV无码精品色午夜麻豆| 日日狠狠久久偷偷色综合免费| 中文字幕无码精品亚洲资源网久久| 精品国产一区二区三区久久久狼 | 国产激情久久久久影院| 青青久久精品国产免费看| 老色鬼久久亚洲AV综合| 久久久久国色AV免费观看| 久久国产亚洲精品无码| 久久无码国产| 99久久精品免费看国产免费| 久久成人国产精品免费软件| 精品国产热久久久福利| 久久66热人妻偷产精品9| 久久婷婷色香五月综合激情| 国产亚州精品女人久久久久久 | 国产A级毛片久久久精品毛片| 无码AV波多野结衣久久| 亚洲精品无码专区久久同性男| 久久中文娱乐网| 久久毛片一区二区| 国产呻吟久久久久久久92| 97久久超碰国产精品2021| 亚洲国产精品无码久久久秋霞2| 久久天天躁狠狠躁夜夜2020老熟妇| 99久久精品影院老鸭窝| 久久香蕉综合色一综合色88| 久久久久女人精品毛片| 国产精品女同久久久久电影院| 久久成人国产精品免费软件| 久久久久高潮综合影院| 亚洲午夜久久久| 狠狠色丁香久久婷婷综合| 97久久国产综合精品女不卡| 无码精品久久久久久人妻中字| 久久青青草原精品国产| 91精品国产色综合久久| 国产成人精品久久亚洲高清不卡| 99久久无码一区人妻|