We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d505d83 + da9f47a commit 927c48aCopy full SHA for 927c48a
2707. Extra Characters in a String1
@@ -0,0 +1,16 @@
1
+class Solution {
2
+public:
3
+ int minExtraChar(string s, vector<string>& d) {
4
+ int n = s.size(), m;
5
+ vector<int> dp(n + 1);
6
+ for (int i{1}; i <= n; ++i) {
7
+ dp[i] = dp[i - 1] + 1;
8
+ for (const string& word : d) {
9
+ m = word.size();
10
+ if (i >= m && s.substr(i - m, m) == word) dp[i] = min(dp[i], dp[i - m]);
11
+ }
12
13
+ return dp[n];
14
15
+};
16
+auto io_opt = [] { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
0 commit comments