题目

https://leetcode.com/problems/maximum-product-of-word-lengths/

题解

中规中矩的题目,中规中矩的思路,不像是一个 medium 题。直接上草稿。

class Solution {public int maxProduct(String[] words) {boolean[][] a = new boolean[words.length][26];for (int i = 0; i < words.length; i++) {for (int j = 0; j < words[i].length(); j++) {a[i][words[i].charAt(j) - 'a'] = true;}}int maxProduct = 0;for (int i = 0; i < words.length; i++) {for (int j = i + 1; j < words.length; j++) {// if (words[i].length() * words[j].length() < maxProduct) continue; // 剪枝(优化效果不明显)int k;for (k = 0; k < words[i].length(); k++) {if (a[j][words[i].charAt(k) - 'a']) break;}if (k == words[i].length()) maxProduct = Math.max(maxProduct, words[i].length() * words[j].length());}}return maxProduct;}
}

leetcode 318. Maximum Product of Word Lengths | 318. 最大单词长度乘积相关推荐

  1. 318. Maximum Product of Word Lengths

    问题:给定一个字符串数组words,找到这样的最大值:length(word[i]) * length(word[j]),words[i]和words[j]没有共同的字母.假设输入字符串只包含小写字母 ...

  2. Maximum Product of Word Lengths

    Maximum Product of Word Lengths 题目链接: https://leetcode.com/problems... public class Solution {public ...

  3. 【LeetCode】Maximum Product Subarray 求连续子数组使其乘积最大

    Add Date 2014-09-23 Maximum Product Subarray Find the contiguous subarray within an array (containin ...

  4. LeetCode Maximum Product of Word Lengths(位操作)

    问题:给出一个字符串数组,要求求出两个没有共同字符的字符串的最大积 思路:第一种方法是直接枚举任意两个字符串,看是否有公共字符,如果没有,则计算乘积,并更新最大值. 第二种方法,因为字符范围是a-z, ...

  5. LeetCode 391. 完美矩形(扫描线) / 318. 最大单词长度乘积 / 563. 二叉树的坡度

    391. 完美矩形 2021.11.16 每日一题 题目描述 给你一个数组 rectangles ,其中 rectangles[i] = [xi, yi, ai, bi] 表示一个坐标轴平行的矩形.这 ...

  6. LeetCode 152. Maximum Product Subarray--动态规划--C++,Python解法

    题目地址:Maximum Product Subarray - LeetCode Given an integer array nums, find the contiguous subarray w ...

  7. LeetCode 628. Maximum Product of Three Numbers

    题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...

  8. LeetCode 152. Maximum Product Subarray

    152. Maximum Product Subarray Find the contiguous subarray within an array (containing at least one ...

  9. LeetCode 318. 最大单词长度乘积(位运算)

    1. 题目 给定一个字符串数组 words,找到 length(word[i]) * length(word[j]) 的最大值,并且这两个单词不含有公共字母.你可以认为每个单词只包含小写字母.如果不存 ...

最新文章

  1. 重构路上遇到的一些兼容性问题
  2. Lync 2010迁移Lync 2013 PART6:迁移CMS
  3. 2015年度最全微课堂笔记精华包
  4. mysql三次握手_TCP的三次握手和四次挥手详解
  5. 8086汇编4位bcd码_51单片机用汇编语言实现BCD码转换
  6. C语言编程中关于负数的%运算的判定。
  7. [Jmeter] 基本使用的总结
  8. java中静态代码块的用法 static用法详解
  9. 【python教程入门学习】Python 正则表达式
  10. cricheditview实现语法高亮和行号_Markdown语法详解及工具介绍
  11. springmvc整合dubbo
  12. java 静态绑定_java的动态绑定和静态绑定
  13. axios 文档中文翻译
  14. Monotonic Renumeration- codeforce
  15. Microsoft Enterprise Library 5.0 系列(二) Cryptography Application Block (高级)
  16. Context.getDir
  17. Matlab学习笔记之Matlab中括号用法
  18. 图像处理的相关数学知识
  19. SU操作说明--SU格式转SEGY格式
  20. api有哪些 javasocket_Java原生Socket API

热门文章

  1. 【数据结构】线性表的链式表示-循环单链表、循环双链表、静态链表
  2. JSP中的include指令
  3. HDU1421 搬寝室
  4. sscanf函数用法详解
  5. 最容易被盗的密码,你中了么?
  6. Netty学习笔记(五)Pipeline
  7. 中台不是万能药,关于中台的思考和尝试
  8. 如何获取Kafka的消费者详情——从Scala到Java的切换
  9. XCode发布IPA离线安装包步骤
  10. AI视觉,视频云新挑战的解决之道