题解 | #字符串长度最大乘积#
字符串长度最大乘积
https://www.nowcoder.com/practice/480caa5ffd164ac8b71caaa6d0f4e6db
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var inputArr=[];
rl.on('line', function(line){
inputArr.push(line);
}).on('close', function(){
console.log(maxProduct(inputArr[0]));
})
function maxProduct(arr){
arr = JSON.parse(arr);
let res = 0;
for(let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
let arr1 = arr[j].split('');
let flag = arr1.every((item) => {
return arr[i].indexOf(item)==-1;
})
if (flag) {
res = Math.max(res, arr1.length*arr[i].length);
}
}
}
return res;
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var inputArr=[];
rl.on('line', function(line){
inputArr.push(line);
}).on('close', function(){
console.log(maxProduct(inputArr[0]));
})
function maxProduct(arr){
arr = JSON.parse(arr);
let res = 0;
for(let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
let arr1 = arr[j].split('');
let flag = arr1.every((item) => {
return arr[i].indexOf(item)==-1;
})
if (flag) {
res = Math.max(res, arr1.length*arr[i].length);
}
}
}
return res;
}