Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
long long validSubstringCount(string word1, string word2) {
int count = 0;
long long ans = 0;
int l = 0, r = 0;
vector<int> map2(27, 0), map1(27, 0);
for (int i = 0; i < word2.size(); i++) {
map2[word2[i] - 'a']++;
}
while (r < word1.size()) {
map1[word1[r] - 'a']++;
if (map1[word1[r] - 'a'] == map2[word1[r] - 'a'])
count += map2[word1[r] - 'a'];
while (count == word2.size()) {
ans += (word1.size() - r);
map1[word1[l] - 'a']--;
if (map1[word1[l] - 'a'] < map2[word1[l] - 'a'])
count -= map2[word1[l] - 'a'];
l++;
}
r++;
}
return ans;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
long long validSubstringCount(string word1, string word2) {
int count = 0;
long long ans = 0;
int l = 0, r = 0;
vector<int> map2(27, 0), map1(27, 0);
for (int i = 0; i < word2.size(); i++) {
map2[word2[i] - 'a']++;
}
while (r < word1.size()) {
map1[word1[r] - 'a']++;
if (map1[word1[r] - 'a'] == map2[word1[r] - 'a'])
count += map2[word1[r] - 'a'];
while (count == word2.size()) {
ans += (word1.size() - r);
map1[word1[l] - 'a']--;
if (map1[word1[l] - 'a'] < map2[word1[l] - 'a'])
count -= map2[word1[l] - 'a'];
l++;
}
r++;
}
return ans;
}
};
22 changes: 22 additions & 0 deletions 740. Delete and Earn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int deleteAndEarn(vector<int>& nums) {
int m = 10001;
int n = nums.size();
int maxVal = 0;
vector<int> f(m, 0);
vector<int> dp(m + 1, 0);

for (int i = 0; i < n; i++) {
f[nums[i]]++;
maxVal = max(maxVal, nums[i]);
}

dp[1] = f[1];
for (int i = 2; i <= maxVal; i++) {
dp[i] = max(dp[i - 1], dp[i - 2] + f[i] * i);
}

return dp[maxVal];
}
};