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 小时前
LeetCode热题100-寻找两个正序数组的中位数
算法·leetcode·职场和发展
踩坑记录3 小时前
leetcode hot100 寻找两个正序数组的中位数 hard 二分查找 双指针
leetcode
superior tigre6 小时前
78 子集
算法·leetcode·深度优先·回溯
superior tigre7 小时前
739 每日温度
算法·leetcode·职场和发展
6Hzlia8 小时前
【Hot 100 刷题计划】 LeetCode 15. 三数之和 | C++ 排序+双指针
c++·算法·leetcode
北顾笙9809 小时前
day37-数据结构力扣
数据结构·算法·leetcode
止语Lab10 小时前
Gin 很好,但你的项目可能需要更多
golang·gin
hopetomorrow11 小时前
学习路之go --go入门
golang
6Hzlia12 小时前
【Hot 100 刷题计划】 LeetCode 189. 轮转数组 | C++ 三次反转经典魔法 (O(1) 空间)
c++·算法·leetcode
KeyonY12 小时前
车联网规则引擎设计之热更新与版本管理
redis·golang·车联网