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
}
相关推荐
夏乌_Wx22 分钟前
练题100天——DAY23:存在重复元素Ⅰ Ⅱ+两数之和
数据结构·算法·leetcode
ada7_6 小时前
LeetCode(python)108.将有序数组转换为二叉搜索树
数据结构·python·算法·leetcode
独自破碎E6 小时前
加油站环路问题
java·开发语言·算法·leetcode
Swift社区7 小时前
LeetCode 445 - 两数相加 II
算法·leetcode·职场和发展
墨染点香7 小时前
LeetCode 刷题【187. 重复的DNA序列】
算法·leetcode·职场和发展
2401_841495648 小时前
【LeetCode刷题】最大子数组和
数据结构·python·算法·leetcode·动态规划·最大值·最大子数组和
鹿角片ljp8 小时前
力扣101.判断对称二叉树-推荐掌握递归
算法·leetcode·职场和发展
2401_841495648 小时前
【LeetCode刷题】最小覆盖字串
数据结构·python·算法·leetcode·字符串·双指针·滑动窗口算法
qk学算法10 小时前
力扣算法——二分最大值最小值
数据结构·算法·leetcode