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;
}
相关推荐
lilili也41 分钟前
visual studio add matlab
c语言·c++
Forever Nore1 小时前
LeetCode 1 两数之和
算法·leetcode·职场和发展
To_OC1 小时前
LC 3 无重复字符的最长子串:从入门滑动窗口到优化写法,再也不怕面试官追问
javascript·算法·leetcode
青 春 记 忆5 小时前
LeetCode 53. 最大子数组和|Python 解法详解
python·算法·leetcode
阿米亚波6 小时前
【C/C++包管理器】vcpkg(by microsoft)
c语言·c++·git·vscode·microsoft·github·vcpkg
SNAKEpc121386 小时前
OpenGL(十一)- 变换管线
c语言·c++·算法·矩阵·图形渲染
小小龙学IT6 小时前
Day 26-27 项目实战:从零构建一个高并发聊天室(epoll + 线程池)
linux·服务器·c语言·开发语言·网络
c238567 小时前
MySQL 基础用法(下):查询进阶与核心特性
android·c语言·c++·mysql
十月的皮皮8 小时前
STM32从零到量产开发:四路继电器工业控制模块开发 - 上位机操作说明书
c语言·stm32·单片机·stm32cubemx
小僧景贤9 小时前
嵌入式C语言 第十一篇:成长路线|嵌入式C工程师完整进阶学习路径(从零到工程级落地|含周期+实战项目)
c语言·开发语言·学习