首页 > 代码库 > [LeetCode] Add Bold Tag in String 字符串中增添加粗标签
[LeetCode] Add Bold Tag in String 字符串中增添加粗标签
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:
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"
Note:
- The given dict won‘t contain duplicates, and its length won‘t exceed 100.
- All the strings in input have length in range [1, 1000].
s
[LeetCode] Add Bold Tag in String 字符串中增添加粗标签
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。