[LeetCode] Bold Words in String 字符串中的加粗单词

Given a set of keywords words and a string S, make all appearances of all keywords in S bold. Any letters between <b> and </b> tags become bold.

The returned string should use the least number of tags possible, and of course the tags should form a valid combination.

For example, given that words = ["ab", "bc"] and S = "aabcd", we should return "a<b>abc</b>d". Note that returning "a<b>a<b>b</b>c</b>d" would use more tags, so it is incorrect.

Note:

  1. words has length in range [0, 50].
  2. words[i] has length in range [1, 10].
  3. S has length in range [0, 500].
  4. All characters in words[i] and S are lowercase letters.

s

原文地址:https://www.cnblogs.com/grandyang/p/8531642.html

时间: 2024-11-11 19:15:45

[LeetCode] Bold Words 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

【C】字符串的输入,求输入字符串中最长的单词

首先,基本目标很简单,就是利用C语言:编写一个函数,输入一行字符,将此行字符中的最长的单词输出. 代码如下: #include<stdio.h> void input(char s[]){ int i=0; for(int c;(c=getchar())!='\n';i++){ s[i]=c; } s[i]='\0';//读取完成,记得对这个字符数组封口 } char* findmax(char s[]){ int max=0,word_length=0,p=0,i=0;//这个p是用来记录最

将字符串中的三个单词的首字母转化成大写

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> //var a = 'welcome to china'; //将字符串中的三个单词的首字母转化成大写:返回Welcome To China; var a = 'welcome to china'; va

LeetCode:Valid Number - 判断字符串中内容是否为数字

1.题目名称 Valid Number(判断字符串中内容是否为数字) 2.题目地址 https://leetcode.com/problems/valid-number/ 3.题目内容 英文:Validate if a given string is numeric. 中文:给出一个字符串,检查这个字符串中内容是否是一个数字 例如:"0"." 0.1"."2e10"是数字,"abc"."1 a"不是数字 4

LEETCODE 003 找出一个字符串中最长的无重复片段

题目: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of

三. Anagram detection problem for string(字符串中回文词汇检测问题)

anagram 相同字母异序词.heart vs earth 1.Our first solution to the anagram problem will check to see that each character in the first string actually occurs in the second. If it is possible to "checkoff" each character, then the two strings must be anag

[CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符

1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure? 这道题让我们判断一个字符串中是否有重复的字符,要求不用特殊的数据结构,这里应该是指哈希表之类的不让用.像普通的整型数组应该还是能用的,这道题的小技巧就是用整型数组来代替哈希表,在之前Bitwise AND of Numbers Range 数

【easy】Number of Segments in a String 字符串中的分段数量

以空格为分隔符,判断一个string可以被分成几部分. 注意几种情况:(1)全都是空格 (2)空字符串(3)结尾有空格 思路: 只要统计出单词的数量即可.那么我们的做法是遍历字符串,遇到空格直接跳过,如果不是空格,则计数器加1,然后用个while循环找到下一个空格的位置,这样就遍历完了一个单词,再重复上面的操作直至结束,就能得到正确结果: class Solution { public: int countSegments(string s) { int res = 0, n = s.size(

C# 正则表达式匹配string字符串中的时间串(yyyyMMdd)

var time = ""; string pattern = @"_(?<time>20\d{6})"; var regResult = Regex.Match(fileName, pattern); if (regResult.Success) { time = regResult.Groups["time"].ToString(); } var uploadDate = DateTime.ParseExact(time, &qu