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
}
相关推荐
Joyner20185 小时前
python-leetcode-从中序与后序遍历序列构造二叉树
算法·leetcode·职场和发展
因兹菜5 小时前
[LeetCode]day9 203.移除链表元素
算法·leetcode·链表
LNsupermali5 小时前
力扣257. 二叉树的所有路径(遍历思想解决)
算法·leetcode·职场和发展
雾月555 小时前
LeetCode LCR180文件组合
算法·leetcode·职场和发展
萌の鱼5 小时前
leetcode 2080. 区间内查询数字的频率
数据结构·c++·算法·leetcode
Tisfy5 小时前
LeetCode 0541.反转字符串 II:模拟
算法·leetcode·字符串·题解
加油,旭杏6 小时前
【go语言】接口
开发语言·后端·golang
labmem18 小时前
Leetcode:541
算法·leetcode·职场和发展
圆圆滚滚小企鹅。8 小时前
刷题记录 HOT100回溯算法-6:79. 单词搜索
笔记·python·算法·leetcode
钓一朵雪10 小时前
【Leetcode刷题记录】45. 跳跃游戏 II--贪心算法
leetcode·贪心算法