Placido_GDD

Parity outlier

Jul 5th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System;
  4.  
  5. public class Kata
  6. {
  7.   public static int Find(int[] integers)
  8.   {
  9.     List<int> Oddlist = new List<int>();
  10.     List<int> EvenList = new List<int>();
  11.    
  12.     int result = 0;
  13.     foreach(int i in integers)
  14.     {
  15.       if(i % 2 == 0)
  16.       {
  17.         EvenList.Add(i);
  18.       }
  19.       else
  20.       {
  21.         Oddlist.Add(i);
  22.       }
  23.     }
  24.    
  25.     if(Oddlist.Count == 1)
  26.     {
  27.       result = Oddlist[0];
  28.     }
  29.     if(EvenList.Count == 1)
  30.     {
  31.       result = EvenList[0];
  32.     }
  33.    
  34.     else
  35.       result = 0;
  36.    
  37.     return result;
  38.   }
  39. }
Add Comment
Please, Sign In to add comment