title: Count Of Occurrences Of A 101 Pattern In A String
signature: pub fn count_of_occurrences_of_a_101_pattern_in_a_string(s: String) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(s: String, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(s), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "1001ab010abc01001".to_string(), 
        2
      ));
      
      println!("TEST-1...{}", driver(
        "1001010001".to_string(), 
        3
      ));
      
      println!("TEST-2...{}", driver(
        "010100010100".to_string(), 
        3
      ));
      
      println!("TEST-3...{}", driver(
        "DLCu".to_string(), 
        0
      ));
      
      println!("TEST-4...{}", driver(
        "7072430592".to_string(), 
        0
      ));
      
      println!("TEST-5...{}", driver(
        "011".to_string(), 
        0
      ));
      
      println!("TEST-6...{}", driver(
        "pnJpypYOza".to_string(), 
        0
      ));
      
      println!("TEST-7...{}", driver(
        "1037".to_string(), 
        0
      ));
      
      println!("TEST-8...{}", driver(
        "111".to_string(), 
        0
      ));
      
      println!("TEST-9...{}", driver(
        "HxK".to_string(), 
        0
      ));
      
  }
source_py: def count_of_occurrences_of_a_101_pattern_in_a_string(s):
      length = len(s)
      oneSeen = False
      count = 0
      for i in range(length):
          if ((s[i] == '1') and oneSeen):
              if (s[(i - 1)] == '0'):
                  count += 1
          if ((s[i] == '1') and (oneSeen == 0)):
              oneSeen = True
          if ((s[i] != '0') and (s[i] != '1')):
              oneSeen = False
      return count
source_cpp: int count_of_occurrences_of_a_101_pattern_in_a_string(string str) {
    int len = str . size ( );
    bool oneSeen = 0;
    int count = 0;
    for ( int i = 0;
    i < len;
    i ++ ) {
      if ( str [ i ] == '1' && oneSeen == 1 ) if ( str [ i - 1 ] == '0' ) count ++;
      if ( str [ i ] == '1' && oneSeen == 0 ) {
        oneSeen = 1;
        continue;
      }
      if ( str [ i ] != '0' && str [ i ] != '1' ) oneSeen = 0;
    }
    return count;
  }