public class Solution {
    public int MaxProduct(string[] words) {
      
      bool flag;
      int pro = 0;
      int N = words.Length;
      
      int[] char_exist;
      char_exist = new int[N];
      Array.Clear(char_exist,0,N);
      
      for(int i=0;i<N;i++) {
              for(int k=0;k<words[i].Length;k++)
                   char_exist[i] |= 1<<(words[i][k] - 'a');
       }
      
      for(int i=0;i<N-1;i++) 
      {    for(int j=i+1;j<N;j++) 
            {   
                flag = true;
                if((char_exist[i] & char_exist[j]) !=0)
                {
                        flag = false;
                }
                if(flag == true)
                    pro = Math.Max((words[i].Length)*(words[j].Length),pro);
                if(pro== int.MaxValue)return pro;
                    
            }   
      }
      return pro;
    }
}

思想 用一个int数组,记录每个word里面出现过哪些字符,两个int之间“与”运算,得知他们是否有共同元素

语言 c#

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-01-28
  • 2021-07-04
  • 2022-12-23
  • 2022-03-07
  • 2022-12-23
猜你喜欢
  • 2022-02-18
  • 2021-12-26
  • 2021-11-13
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案