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
}
相关推荐
黎雁·泠崖2 分钟前
栈与队列实战通关:3道经典OJ题深度解析
c语言·数据结构·leetcode
AlenTech7 小时前
160. 相交链表 - 力扣(LeetCode)
数据结构·leetcode·链表
sin_hielo8 小时前
leetcode 1161(BFS)
数据结构·算法·leetcode
iAkuya10 小时前
(leetcode)力扣100 34合并K个升序链表(排序,分治合并,优先队列)
算法·leetcode·链表
放荡不羁的野指针11 小时前
leetcode150题-字符串
数据结构·算法·leetcode
橘颂TA11 小时前
【剑斩OFFER】算法的暴力美学——存在重复元素Ⅱ
算法·leetcode·哈希算法·散列表·结构与算法
cg501711 小时前
力扣数据库——组合两个表
sql·算法·leetcode
2501_9417987311 小时前
面向微服务分布式事务补偿与最终一致性的互联网系统高可用设计与多语言工程实践分享
leetcode·模拟退火算法
ada7_12 小时前
LeetCode(python)22.括号生成
开发语言·数据结构·python·算法·leetcode·职场和发展
YuTaoShao12 小时前
【LeetCode 每日一题】1161. 最大层内元素和——BFS
算法·leetcode·宽度优先