Skip to content

Commit eb59c20

Browse files
committed
202208270530
1 parent d0313f6 commit eb59c20

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

independent/202208270530/0.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"abaac"

independent/202208270530/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
给你一个字符串,长度最大1e5,求最长连续子串使得里面每个字符出现的个数是偶数,只考虑小写字母

independent/202208270530/main.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
3+
*/
4+
5+
#include <bits/stdc++.h>
6+
#include "../../lib/LeetCodeInputTemplate.hpp"
7+
#include "solution.cpp"
8+
using namespace std;
9+
10+
typedef vector<int> vi;
11+
typedef vector<vector<int>> vvi;
12+
13+
int main()
14+
{
15+
LeetCodeInput li("0.in");
16+
17+
auto l0 = li.get<string>(0);
18+
19+
chrono::steady_clock::time_point begin = chrono::steady_clock::now();
20+
Solution solution;
21+
auto output = solution.solution(l0);
22+
chrono::steady_clock::time_point end = chrono::steady_clock::now();
23+
cout << "Time difference = " << chrono::duration_cast<chrono::microseconds> (end - begin).count() << "µs" << endl;
24+
25+
cout << output << endl;
26+
27+
// for (int i: output){
28+
// cout << i << ' ';
29+
// }
30+
31+
// for (auto i: output){
32+
// for (int j: i){
33+
// cout << j << ' ';
34+
// }
35+
// cout << '\n';
36+
// }
37+
38+
return 0;
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
3+
time: O()
4+
space: O()
5+
6+
Runtime:
7+
Memory Usage:
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
12+
using namespace std;
13+
14+
#define all(x) begin(x), end(x)
15+
typedef vector<int> vi;
16+
typedef vector<vector<int>> vvi;
17+
18+
class Solution {
19+
public:
20+
int solution(string s) {
21+
int n = size(s);
22+
unordered_map<uint32_t, int> pos_by_val;
23+
uint32_t status = 0;
24+
int ans = 0;
25+
for (int i=0; i<n; ++i){
26+
status ^= s[i]-'a';
27+
auto res = pos_by_val.emplace(status, i);
28+
if (!res.second){
29+
ans = max(ans, i-(*res.first).second);
30+
}
31+
}
32+
return ans;
33+
}
34+
};
35+
36+
const static auto initialize = [] {
37+
std::ios::sync_with_stdio(false);
38+
std::cin.tie(nullptr);
39+
std::cout.tie(nullptr);
40+
return nullptr;
41+
}();

0 commit comments

Comments
 (0)