Ad
Code
Diff
  • //Given 2 Arrays, Return True if arrays contain common item, else false.
    //e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
    //input : 2 arrays
    //output: bool
    using System.Collections.Generic;
    using System.Linq;
    
    public class Kata
    {
      public static bool ContainsCommonItem(char[] a, char[] b)
      {
        return a != null ? b != null ? new List<char>(a).Intersect(new List<char>(b)).Count() > 0 : false: false;
      }
       
    }
    • //Given 2 Arrays, Return True if arrays contain common item, else false.
    • //e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
    • //input : 2 arrays
    • //output: bool
    • using System.Collections.Generic;
    • using System.Linq;
    • public class Kata{
    • public static bool ContainsCommonItem(char[] a, char[] b){
    • if (!(a?.Any()??false) || !(b?.Any()??false))
    • return false; // empty/null arrays have nothing in common
    • return a == b || ByHashSetOverlap(a, b);
    • }
    • private static bool ByHashSetOverlap(char[] a,char[]b)
    • public class Kata
    • {
    • public static bool ContainsCommonItem(char[] a, char[] b)
    • {
    • HashSet<char> ha = new HashSet<char>(a);
    • HashSet<char> hb = new HashSet<char>(b);
    • return ha.Overlaps(hb);
    • return a != null ? b != null ? new List<char>(a).Intersect(new List<char>(b)).Count() > 0 : false: false;
    • }
    • }
    • }