Golang | Leetcode Golang题解之第318题最大单词长度乘积

题目:

题解:

Go 复制代码
func maxProduct(words []string) (ans int) {
    masks := map[int]int{}
    for _, word := range words {
        mask := 0
        for _, ch := range word {
            mask |= 1 << (ch - 'a')
        }
        if len(word) > masks[mask] {
            masks[mask] = len(word)
        }
    }

    for x, lenX := range masks {
        for y, lenY := range masks {
            if x&y == 0 && lenX*lenY > ans {
                ans = lenX * lenY
            }
        }
    }
    return
}
相关推荐
hanlin0318 小时前
刷题笔记:力扣第704、977、209题(数组相关)
笔记·算法·leetcode
Wang's Blog19 小时前
Go-Zero项目开发38:深入限流器实现与应用
开发语言·golang·go-zero
Rabitebla19 小时前
C++ 内存管理全面复习:从内存分布到 operator new/delete
java·c语言·开发语言·c++·算法·leetcode
xcLeigh19 小时前
Go入门:main包与main函数的特殊地位
开发语言·后端·golang
玖玥拾19 小时前
LeetCode 58 最后一个单词的长度
算法·leetcode
hanlin0320 小时前
刷题笔记:力扣第19题-删除链表的倒数第N个结点
笔记·leetcode·链表
菜鸟的升级路20 小时前
C语言栈刷题:LeetCode 20 有效的括号完整解题笔记
c语言·笔记·leetcode
Lsir10110_21 小时前
【力扣hot100】矩阵题通关复盘
算法·leetcode·矩阵
退休倒计时21 小时前
【每日一题】LeetCode 207. 课程表 TypeScript
算法·leetcode·typescript
玖玥拾1 天前
LeetCode 80 删除有序数组中的重复项 II
算法·leetcode