Advertisement
Placido_GDD

ArrayLeaders

Jun 7th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public static class Kata
  5. {
  6. public static int[] ArrayLeaders(int[] numbers)
  7. {
  8. List<int> listOfnums = new List<int>();
  9. int elementSum = 0;
  10. for(int x = 0;x < numbers.Length;x++)
  11. {
  12. if(x + 1 < numbers.Length)
  13. {
  14. for(int y = x + 1;y < numbers.Length;y++)
  15. {
  16. elementSum += numbers[y];
  17. }
  18. }
  19. if(x + 1 >= numbers.Length)
  20. {
  21. elementSum = 0;
  22. }
  23. if(elementSum < numbers[x])
  24. {
  25. listOfnums.Add(numbers[x]);
  26. }
  27. }
  28. int[] result = listOfnums.ToArray();
  29. return result;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement