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
}
相关推荐
TracyCoder1231 小时前
LeetCode Hot100(46/100)——74. 搜索二维矩阵
算法·leetcode·矩阵
im_AMBER2 小时前
Leetcode 119 二叉树展开为链表 | 路径总和
数据结构·学习·算法·leetcode·二叉树
苏荷水2 小时前
万字总结LeetCode100(持续更新...)
java·算法·leetcode·职场和发展
TracyCoder1234 小时前
LeetCode Hot100(50/100)——153. 寻找旋转排序数组中的最小值
算法·leetcode·职场和发展
化学在逃硬闯CS5 小时前
Leetcode110.平衡二叉树
数据结构·c++·算法·leetcode
爱coding的橙子5 小时前
Day87:2.12:leetcode 动态规划8道题,用时3h
算法·leetcode·动态规划
努力学算法的蒟蒻6 小时前
day84(2.12)——leetcode面试经典150
算法·leetcode·面试
程序员酥皮蛋6 小时前
hot 100 第二十三题 23.反转链表
数据结构·算法·leetcode·链表
TracyCoder1236 小时前
LeetCode Hot100(51/100)——155. 最小栈
数据结构·算法·leetcode