LC 1542. Find Longest Awesome Substring

link

class Solution {
public:
    int longestAwesome(string s) {
        int n=s.size();
        vector<int> dp(1<<10,n);
        int res=1;
        dp[0]=-1;
        int mask=0;
        for(int i=0;i<n;i++){
            char c=s[i];
            mask^=(1<<(c-'0'));
            res=max(res,i-dp[mask]);
            for(int j=0;j<10;j++){
                res=max(res,i-dp[mask^(1<<j)]);
            }
            dp[mask]=min(dp[mask],i);
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/FEIIEF/p/13467893.html