[抄題]:算法
Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b>
and </b>
to wrap the substrings in s that exist in dict. If two such substrings overlap, you need to wrap them together by only one pair of closed bold tag. Also, if two substrings wrapped by bold tags are consecutive, you need to combine them. 數據結構
Example 1:app
Input: s = "abcxyz123" dict = ["abc","123"] Output: "<b>abc</b>xyz<b>123</b>"
Example 2:優化
Input: s = "aaabbcc" dict = ["aaa","aab","bc"] Output: "<b>aaabbc</b>c"
[暴力解法]:spa
時間分析:debug
空間分析:code
[優化後]:get
時間分析:string
空間分析:it
[奇葩輸出條件]:
[奇葩corner case]:
[思惟問題]:
[一句話思路]:
[輸入量]:空: 正常狀況:特大:特小:程序裏處理到的特殊狀況:異常狀況(不合法不合理的輸入):
[畫圖]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分鐘肉眼debug的結果]:
[總結]:
[複雜度]:Time complexity: O() Space complexity: O()
[英文數據結構或算法,爲何不用別的數據結構或算法]:
[關鍵模板化代碼]:
[其餘解法]:
[Follow Up]:
[LC給出的題目變變變]:
[代碼風格] :