Check if two strings have a common substring | C # program to check if two strings have common substring ; function to return true if strings have common substring and no if strings have no common substring ; vector for storing character occurrences ; increment vector index for every character of str1 ; checking common substring of str2 in str1 ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static bool twoStrings ( String s1 , String s2 ) { bool [ ] v = new bool [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) v [ i ] = false ; for ( int i = 0 ; i < s1 . Length ; i ++ ) v [ s1 [ i ] - ' a ' ] = true ; for ( int i = 0 ; i < s2 . Length ; i ++ ) if ( v [ s2 [ i ] - ' a ' ] ) return true ; return false ; } public static void Main ( ) { String str1 = " hello " ; String str2 = " world " ; if ( twoStrings ( str1 , str2 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }