Their thinking

Every five minutes

  1. I started with the idea of a two-layer loop, like sort algorithm, to compare two strings in pairs, but to determine whether two strings have inclusion problems, so I wrote one firstisSameTool function
  2. defineresReturn the value ifisSameThere is no returntrue, then the value of this comparison is valid, andresCompare and update when you’re olderres

Time: about 5-7 minutes

code

/ * * *@param {string[]} words
 * @return {number}* /

// Do two strings have the same place
function isSame(str1,str2){
    for(let i=0; i<str1.length; i++){if(str2.includes(str1[i]))return true; }}var maxProduct = function(words) {
    let res = 0;

    // Compare two layers
    for(let i=0; i<words.length; i++){for(let j=i+1; j<words.length; j++){// If so, calculate and compare the size with res
            if(isSame(words[i],words[j])! = =true) {const _res = words[i].length*words[j].length;
                if(_res>res)res = _res; }}}return res;
};
Copy the code