不是,这 O(n) 的做法,怎么跑出来 T 的啊?
实在想不出来。有大佬可否指点一下。
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
while(!isdigit(c)) {if(c == '-') f = -f; c = getchar();}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
x *= f;
}
const int N = 1e5 + 1;
const int M = (1 << 8);
char s[N], t[N];
int x[M], y[M];
int main() {
scanf("%s%s", s, t);
for(int i = 0; i < strlen(s); i++) x[s[i]]++;
for(int i = 0; i < strlen(t); i++) y[t[i]]++;
int Ans = 0;
for(int i = 'a'; i <= 'z'; i++) Ans += min(x[i], y[i]);
printf("%d\n", Ans);
return 0;
}