Advertisement
Placido_GDD

hollowArrays

Jun 22nd, 2022
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. public class Kata
  4. {
  5.   public static bool IsHollow(int[] x)
  6.   {
  7.     int count = x.Length;
  8.     int preceeding = 0;
  9.     int following = 0;
  10.     int zeroes = 0;
  11.     bool result = false;
  12.    
  13.     for(int a = 0;a < count;a++)
  14.     {
  15.       if(x[a] != 0)
  16.       {
  17.         preceeding++;
  18.       }
  19.       if(x[a] == 0)
  20.       {
  21.         break;
  22.       }
  23.     }
  24.    
  25.     for(int b = count - 1;b > 0;b--)
  26.     {
  27.       if(x[b] != 0)
  28.       {
  29.         following++;
  30.       }
  31.       if(x[b] == 0)
  32.       {
  33.         break;
  34.       }
  35.     }
  36.    
  37.     for(int c = 0;c < count;c++)
  38.     {
  39.       if(x[c] == 0)
  40.       {
  41.         zeroes++;
  42.       }
  43.     }
  44.    
  45.     if(following == preceeding && zeroes >= 3)
  46.     {
  47.       result = true;
  48.     }
  49.     else
  50.     {
  51.       result = false;
  52.     }
  53.    
  54.     return result;
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement