classSolution { public: stringboldWords(vector<string>& words, string S){ int n = size(S); vector<bool> bold(n); for (constauto &w : words) { int p = -1; while (true) { p = S.find(w, p + 1); if (p == -1) break; fill_n(begin(bold) + p, size(w), true); } } string res; for (int i = 0; i < n; ++i) { if (bold[i] && (i == 0 || !bold[i - 1])) { res += "<b>"; } res += S[i]; if (bold[i] && (i == n - 1 || !bold[i + 1])) { res += "</b>"; } } return res; } };