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
}
相关推荐
参.商.11 小时前
【Day41】143. 重排链表
leetcode·golang
Zaly.14 小时前
【Python刷题】LeetCode 1727 重新排列后的最大子矩阵
算法·leetcode·矩阵
捧 花14 小时前
最小生成树算法(Go)
golang·最小生成树·kruskal·prim
添尹15 小时前
Go语言基础之数组
后端·golang
liurunlin88816 小时前
Go环境搭建(vscode调试)
开发语言·vscode·golang
memcpy017 小时前
LeetCode 1456. 定长子串中元音的最大数目【定长滑窗模板题】中等
算法·leetcode·职场和发展
玛丽莲茼蒿17 小时前
LeetCode hot100【相交链表】【简单】
算法·leetcode·职场和发展
wen__xvn17 小时前
力扣模拟题刷题
算法·leetcode
不要秃头的小孩17 小时前
力扣刷题——111.二叉树的最小深度
数据结构·python·算法·leetcode
We་ct18 小时前
LeetCode 35. 搜索插入位置:二分查找的经典应用
前端·算法·leetcode·typescript·个人开发