C语言 | Leetcode C语言题解之第318题最大单词长度乘积

题目:

题解:

cpp 复制代码
int maxProduct(char ** words, int wordsSize){
    int masks[wordsSize];
    memset(masks, 0, sizeof(masks));
    for(int i = 0; i < wordsSize; ++i) {
        int len = strlen(words[i]);
        for(int j = 0; j < len; ++j) {
            masks[i] |= 1 << (words[i][j] - 'a');
        }
    }

    int res = 0;
    for(int i = 0; i < wordsSize; ++i) {
        for(int j = i + 1; j < wordsSize; ++j) {
            if((masks[i] & masks[j]) == 0) {
                res = fmax(res, strlen(words[i]) * strlen(words[j]));
            }
        }
    }

    return res;
}
相关推荐
熬了夜的程序员8 分钟前
【LeetCode】74. 搜索二维矩阵
线性代数·算法·leetcode·职场和发展·矩阵·深度优先·动态规划
坚持编程的菜鸟9 分钟前
LeetCode每日一题——矩阵置0
c语言·算法·leetcode·矩阵
坚持编程的菜鸟6 小时前
LeetCode每日一题——困于环中的机器人
c语言·算法·leetcode·机器人
Aurorar0rua7 小时前
C Primer Plus Notes 09
java·c语言·算法
我是华为OD~HR~栗栗呀11 小时前
华为od-21届考研-C++面经
java·c语言·c++·python·华为od·华为·面试
oioihoii11 小时前
C++ 中的类型转换:深入理解 static_cast 与 C风格转换的本质区别
java·c语言·c++
ytttr87311 小时前
C语言实现Modbus TCP/IP协议客户端-服务器
服务器·c语言·tcp/ip
我要学脑机12 小时前
C语言面试题问题+答案(claude生成)
c语言·开发语言
今麦郎xdu_13 小时前
【Linux系统】命令行参数和环境变量
linux·服务器·c语言·c++
Vanranrr15 小时前
nullptr vs NULL:C/C++ 空指针的演变史
c语言·c++