leetcode 318. Maximum Product of Word Lengths | 318. 最大单词长度乘积
题目
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. 最大单词长度乘积相关推荐
- 318. Maximum Product of Word Lengths
问题:给定一个字符串数组words,找到这样的最大值:length(word[i]) * length(word[j]),words[i]和words[j]没有共同的字母.假设输入字符串只包含小写字母 ...
- Maximum Product of Word Lengths
Maximum Product of Word Lengths 题目链接: https://leetcode.com/problems... public class Solution {public ...
- 【LeetCode】Maximum Product Subarray 求连续子数组使其乘积最大
Add Date 2014-09-23 Maximum Product Subarray Find the contiguous subarray within an array (containin ...
- LeetCode Maximum Product of Word Lengths(位操作)
问题:给出一个字符串数组,要求求出两个没有共同字符的字符串的最大积 思路:第一种方法是直接枚举任意两个字符串,看是否有公共字符,如果没有,则计算乘积,并更新最大值. 第二种方法,因为字符范围是a-z, ...
- LeetCode 391. 完美矩形(扫描线) / 318. 最大单词长度乘积 / 563. 二叉树的坡度
391. 完美矩形 2021.11.16 每日一题 题目描述 给你一个数组 rectangles ,其中 rectangles[i] = [xi, yi, ai, bi] 表示一个坐标轴平行的矩形.这 ...
- LeetCode 152. Maximum Product Subarray--动态规划--C++,Python解法
题目地址:Maximum Product Subarray - LeetCode Given an integer array nums, find the contiguous subarray w ...
- LeetCode 628. Maximum Product of Three Numbers
题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...
- LeetCode 152. Maximum Product Subarray
152. Maximum Product Subarray Find the contiguous subarray within an array (containing at least one ...
- LeetCode 318. 最大单词长度乘积(位运算)
1. 题目 给定一个字符串数组 words,找到 length(word[i]) * length(word[j]) 的最大值,并且这两个单词不含有公共字母.你可以认为每个单词只包含小写字母.如果不存 ...
最新文章
- 重构路上遇到的一些兼容性问题
- Lync 2010迁移Lync 2013 PART6:迁移CMS
- 2015年度最全微课堂笔记精华包
- mysql三次握手_TCP的三次握手和四次挥手详解
- 8086汇编4位bcd码_51单片机用汇编语言实现BCD码转换
- C语言编程中关于负数的%运算的判定。
- [Jmeter] 基本使用的总结
- java中静态代码块的用法 static用法详解
- 【python教程入门学习】Python 正则表达式
- cricheditview实现语法高亮和行号_Markdown语法详解及工具介绍
- springmvc整合dubbo
- java 静态绑定_java的动态绑定和静态绑定
- axios 文档中文翻译
- Monotonic Renumeration- codeforce
- Microsoft Enterprise Library 5.0 系列(二) Cryptography Application Block (高级)
- Context.getDir
- Matlab学习笔记之Matlab中括号用法
- 图像处理的相关数学知识
- SU操作说明--SU格式转SEGY格式
- api有哪些 javasocket_Java原生Socket API