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;
}
相关推荐
喵了meme2 小时前
C语言实战2
c语言·开发语言·网络
网易独家音乐人Mike Zhou3 小时前
【嵌入式模块芯片开发】LP87524电源PMIC芯片配置流程,给雷达供电的延时上电时序及API函数
c语言·stm32·单片机·51单片机·嵌入式·电源·毫米波雷达
自学小白菜3 小时前
每周刷题 - 第三周 - 双指针专题 - 02
python·算法·leetcode
小立爱学习3 小时前
ARM64 指令 --- CASP / CASPA / CASPL / CASPAL
linux·c语言
不能只会打代码4 小时前
力扣--3433. 统计用户被提及情况
java·算法·leetcode·力扣
武汉唯众智创4 小时前
职业院校C语言程序设计(AIGC版)课程教学解决方案
c语言·开发语言·aigc·程序设计·c语言程序设计·c语言程序设计实训室
qq_401700414 小时前
C语言void*
c语言·开发语言
程芯带你刷C语言简单算法题5 小时前
Day28~实现strlen、strcpy、strncpy、strcat、strncat
c语言·c++·算法·c
如竟没有火炬5 小时前
四数相加贰——哈希表
数据结构·python·算法·leetcode·散列表