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;
}
相关推荐
郝学胜-神的一滴37 分钟前
Effective STL 条款 17:用 swap 技巧去掉多余容量
c语言·开发语言·数据结构·c++·算法·rpc
Nazarick3 小时前
力扣LeetCode热题75题(1)
java·算法·leetcode·力扣
16月6日-晴3 小时前
斐波那契数列题解
算法·leetcode
烟烟Abandon3 小时前
FFmpeg开发基础之 C 语言编译器
c语言·开发语言·ffmpeg
Zwawa5 小时前
断电后参数为什么全没了:把小车配置安全地存进 Flash
c语言·单片机·嵌入式
Tisfy6 小时前
LeetCode 3561.移除相邻字符:栈(相邻相消)
算法·leetcode·字符串·题解·栈·相邻相消
羊在吃青草6 小时前
C语言之数组
c语言·数据结构
烟烟Abandon7 小时前
FFmpeg开发基础之 C 语言中的文件操作
c语言·ffmpeg
金榜题名萱9 小时前
蓝桥杯|石子合并(区间动态规划)
c语言·数据结构·c++·算法·蓝桥杯·动态规划
Navigator_Z10 小时前
LeetCode //C - 1332. Remove Palindromic Subsequences
c语言·算法·leetcode