Check if given Binary string follows then given condition or not | C # program for the above approach ; Function to check if the String follows rules or not ; Check for the first condition ; Check for the third condition ; Check for the second condition ; Driver Code ; Given String str ; Function call
using System ; class GFG { static bool checkrules ( String s ) { if ( s . Length == 0 ) return true ; if ( s [ 0 ] != '1' ) return false ; if ( s . Length > 2 ) { if ( s [ 1 ] == '0' && s [ 2 ] == '0' ) return checkrules ( s . Substring ( 3 ) ) ; } return checkrules ( s . Substring ( 1 ) ) ; } public static void Main ( String [ ] args ) { String str = "1111" ; if ( checkrules ( str ) ) { Console . Write ( " Valid ▁ String " ) ; } else { Console . Write ( " Invalid ▁ String " ) ; } } }