Skip to content

Commit 10b4f82

Browse files
Added day 17, day21, day22 solutions
1 parent b65fe73 commit 10b4f82

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Solution {
2+
public:
3+
bool checkInclusion(string s1, string s2) {
4+
if(s2.size() < s1.size()) return false;
5+
6+
std::vector<int> vs1(26, 0);
7+
8+
for(const auto &el: s1)
9+
{
10+
vs1[el - 'a']++;
11+
}
12+
13+
std::vector<int> vtmp(26, 0);
14+
const std::string tmp = s2.substr(0, s1.size());
15+
16+
for(const auto &el: tmp)
17+
{
18+
vtmp[el - 'a']++;
19+
}
20+
21+
if(vtmp == vs1)
22+
{
23+
return true;
24+
}
25+
26+
for(size_t i = 1; i <= s2.size() - s1.size(); i++)
27+
{
28+
const auto c1 = s2[i-1];
29+
const auto c2 = s2[i+s1.size()-1];
30+
31+
vtmp[c1 - 'a']--;
32+
vtmp[c2 - 'a']++;
33+
34+
if(vtmp == vs1)
35+
{
36+
return true;
37+
}
38+
}
39+
40+
return false;
41+
}
42+
};
File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
string frequencySort(string s) {
4+
if(s.empty()) return "";
5+
map<char,int> m;
6+
for(auto c : s) m[c]++;
7+
vector<pair<int,int>> values(m.begin(),m.end());
8+
9+
sort(values.begin(),values.end(),[](const pair<int,int>& a, const pair<int,int>& b){
10+
return a.second > b.second;
11+
});
12+
13+
string result = "";
14+
for(auto [k, v] : values){
15+
while(v--){
16+
result.push_back(k);
17+
}
18+
}
19+
return result;
20+
}
21+
};

0 commit comments

Comments
 (0)