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;
}
相关推荐
无敌最俊朗@5 小时前
力扣hot100-206反转链表
算法·leetcode·链表
Kuo-Teng5 小时前
LeetCode 279: Perfect Squares
java·数据结构·算法·leetcode·职场和发展
CoderYanger6 小时前
B.双指针——3194. 最小元素和最大元素的最小平均值
java·开发语言·数据结构·算法·leetcode·职场和发展·1024程序员节
小曹要微笑8 小时前
STM32各系列时钟树详解
c语言·stm32·单片机·嵌入式硬件·算法
inputA8 小时前
【LwIP源码学习8】netbuf源码分析
android·c语言·笔记·嵌入式硬件·学习
前进的李工8 小时前
LeetCode hot100:094 二叉树的中序遍历:从递归到迭代的完整指南
python·算法·leetcode·链表·二叉树
吃着火锅x唱着歌10 小时前
LeetCode 面试题 16.24.数对和
算法·leetcode·职场和发展
Dream it possible!10 小时前
LeetCode 面试经典 150_二叉树层次遍历_二叉树的层平均值(82_637_C++_简单)
c++·leetcode·面试·二叉树
Wenhao.10 小时前
LeetCode Hot100 每日温度
数据结构·算法·leetcode·golang
吃着火锅x唱着歌11 小时前
LeetCode 1679.K和数对的最大数目
算法·leetcode·职场和发展