题解 | 最大字母矩阵

最大字母矩阵

https://www.nowcoder.com/practice/270ff3b150704f8795fd4a944a7e043a

class AlphaMatrix {
  public:
    int findAlphaMatrix(vector<string> dic, int n) {
        // write code here
        int maxArea = 0;

        for (int l = 0; l < 50; ++l) {
            for (int r = l; r < 50; ++r) {
                unordered_map<string, int> count;
                for (const string& word : dic) {
                    if (r < word.size()) {
                        string sub = word.substr(l, r - l + 1);
                            count[sub]++;
                    }
                }
                for (const auto& [s, c] : count) {
                    int area = (r - l + 1) * c;
                    maxArea = max(maxArea, area);
                }
            }
        }
        return maxArea;
    }
};

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务