leetcod addboldtag Java

题目:

Given a string s and a list of strings dict, you need to add a closed pair of bold tag  and  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:
"abcxyz123"

 

Example 2:

Input: 
s = "aaabbcc"
dict = ["aaa","aab","bc"]
Output:
"aaabbcc"

java代码:

public static String AddBoldTag(String s,String[] dict)
	{
		String result="";
		int n=s.length(),end=0;
		boolean[] bold=new boolean[n];
		
		for(int i=0;ii;
		}
		
		for(int i=0;i";
				i=j-1;
			}
		}
		System.out.println(Arrays.toString(bold));
		return result;
	}


你可能感兴趣的:(LeetCode题解)