当前位置: 首页 > news >正文

Java | Leetcode Java题解之第318题最大单词长度乘积

题目:

题解:

class Solution {public int maxProduct(String[] words) {Map<Integer, Integer> map = new HashMap<Integer, Integer>();int length = words.length;for (int i = 0; i < length; i++) {int mask = 0;String word = words[i];int wordLength = word.length();for (int j = 0; j < wordLength; j++) {mask |= 1 << (word.charAt(j) - 'a');}if (wordLength > map.getOrDefault(mask, 0)) {map.put(mask, wordLength);}}int maxProd = 0;Set<Integer> maskSet = map.keySet();for (int mask1 : maskSet) {int wordLength1 = map.get(mask1);for (int mask2 : maskSet) {if ((mask1 & mask2) == 0) {int wordLength2 = map.get(mask2);maxProd = Math.max(maxProd, wordLength1 * wordLength2);}}}return maxProd;}
}
http://www.lryc.cn/news/416221.html

相关文章:

  • 科普文:JUC系列之多线程门闩同步器Condition的使用和源码解读
  • Stable Diffusion绘画 | 图生图-基础使用介绍—提示词反推
  • 正点原子imx6ull-mini-Linux驱动之Linux SPI 驱动实验(22)
  • TypeScript 函数
  • C++ : namespace,输入与输出,函数重载,缺省参数
  • 目标检测 | yolov1 原理和介绍
  • excel中有些以文本格式存储的数值如何批量转换为数字
  • 原神升级计划数据表:4个倒计时可以修改提示信息和时间,可以点击等级、命座、天赋、备注进行修改。
  • YoloV10 论文翻译(Real-Time End-to-End Object Detection)
  • 第R1周:RNN-心脏病预测
  • Golang | Leetcode Golang题解之第321题拼接最大数
  • 远程连接本地虚拟机失败问题汇总
  • WebRTC 初探
  • Python:read,readline和readlines的区别
  • 重生之我学编程
  • 如何将PostgreSQL的数据实时迁移到SelectDB?
  • 关于c语言的const 指针
  • 万能门店小程序开发平台功能源码系统 带完整的安装代码包以及安装搭建教程
  • C#初级——字典Dictionary
  • git版本控制的底层实现
  • 深入解析数据处理的技术与实践
  • python-调用c#代码
  • 构建铁路安全防线:EasyCVR视频+AI智能分析赋能铁路上道作业高效监管
  • openai command not found (mac)
  • 鸿蒙(API 12 Beta2版)NDK开发【LLDB高性能调试器】调试和性能分析
  • HAL库源码移植与使用之DMA
  • Scrapy爬虫框架介绍、创建Scrapy项目
  • 如何监测某个进程是否退出(C++)?
  • Python:Neo 库读取 ABF 文件,数据格式详解
  • 【Linux】网络基础_3