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;
}
相关推荐
杜子不疼.9 小时前
Ascend_C自定义算子开发
c语言·开发语言
小乔的编程内容分享站10 小时前
C语言笔记之函数
c语言·笔记
王老师青少年编程10 小时前
2024年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第2题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
杜子不疼.10 小时前
基于ATVC模板库的Ascend C Vector算子快速开发指南
c语言·开发语言·mfc
TracyCoder12310 小时前
LeetCode Hot100(27/100)——94. 二叉树的中序遍历
算法·leetcode
C++ 老炮儿的技术栈10 小时前
Qt Creator中不写代如何设置 QLabel的颜色
c语言·开发语言·c++·qt·算法
艾莉丝努力练剑11 小时前
【Linux:文件】基础IO
linux·运维·c语言·c++·人工智能·io·文件
you-_ling11 小时前
IO编程相关知识
c语言·vscode
小龙报11 小时前
【51单片机】深度解析 51 串口 UART:原理、配置、收发实现与工程化应用全总结
c语言·开发语言·c++·stm32·单片机·嵌入式硬件·51单片机
承渊政道11 小时前
C++学习之旅【C++中模板进阶内容介绍】
c语言·c++·笔记·学习·visual studio