Find if an array contains a string with one mismatch | C # program to find if given string is present with one mismatch . ; If the array is empty ; If sizes are same ; If first mismatch ; Second mismatch ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static bool check ( List < String > list , String s ) { int n = ( int ) list . Count ; if ( n == 0 ) { return false ; } for ( int i = 0 ; i < n ; i ++ ) { if ( list [ i ] . Length != s . Length ) { continue ; } bool diff = false ; for ( int j = 0 ; j < ( int ) list [ i ] . Length ; j ++ ) { if ( list [ i ] [ j ] != s [ j ] ) { if ( ! diff ) { diff = true ; } else { diff = false ; break ; } } } if ( diff ) { return true ; } } return false ; } public static void Main ( String [ ] args ) { List < String > s = new List < String > ( ) ; s . Add ( " bana " ) ; s . Add ( " apple " ) ; s . Add ( " banacb " ) ; s . Add ( " bonanza " ) ; s . Add ( " banamf " ) ; Console . WriteLine ( check ( s , " banana " ) == true ? 1 : 0 ) ; } }