首页 > 其他 > 详细

[LeetCode] Add Bold Tag in String 字符串中增添加粗标签

时间:2017-06-18 09:16:57      阅读:899      评论:0      收藏:0      [点我收藏+]

 

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:

  1. The given dict won‘t contain duplicates, and its length won‘t exceed 100.
  2. All the strings in input have length in range [1, 1000].

 

s

 

[LeetCode] Add Bold Tag in String 字符串中增添加粗标签

原文:http://www.cnblogs.com/grandyang/p/7043394.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!