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
}
相关推荐
leoufung4 小时前
用 DFS 拓扑排序吃透 LeetCode 210:Course Schedule II
算法·leetcode·深度优先
Swift社区5 小时前
LeetCode 443. 压缩字符串
leetcode·职场和发展·蓝桥杯
ada7_5 小时前
LeetCode(python)——543.二叉树的直径
数据结构·python·算法·leetcode·职场和发展
sprintzer5 小时前
11.26-12.05力扣栈刷题
算法·leetcode·职场和发展
sin_hielo5 小时前
leetcode 3578
数据结构·算法·leetcode
前端小白在前进5 小时前
力扣刷题:无重复字符的最长子串
算法·leetcode·职场和发展
卿雪5 小时前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
好易学·数据结构7 小时前
可视化图解算法72:斐波那契数列
数据结构·算法·leetcode·动态规划·力扣·牛客网
CoderYanger8 小时前
动态规划算法-子数组、子串系列(数组中连续的一段):21.乘积最大子数组
开发语言·算法·leetcode·职场和发展·动态规划·1024程序员节
CoderYanger8 小时前
A.每日一题——3432. 统计元素和差值为偶数的分区方案
java·数据结构·算法·leetcode·1024程序员节