Check if all the 1 's in a binary string are equidistant or not | C # implementation of the approach ; Function that returns true if all the 1 's in the binary string s are equidistant ; Initialize vector to store the position of 1 's ; Store the positions of 1 's ; Size of the position vector ; If condition isn 't satisfied ; Drivers code
using System ; using System . Collections . Generic ; class GFG { static bool check ( String s , int l ) { List < int > pos = new List < int > ( ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( s [ i ] == '1' ) { pos . Add ( i ) ; } } int t = pos . Count ; for ( int i = 1 ; i < t ; i ++ ) { if ( ( pos [ i ] - pos [ i - 1 ] ) != ( pos [ 1 ] - pos [ 0 ] ) ) return false ; } return true ; } public static void Main ( String [ ] args ) { String s = "100010001000" ; int l = s . Length ; if ( check ( s , l ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }