반응형
문제
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.
ex)
Kata.MoveZeroes(new int[] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1}) => new int[] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0}
풀이
public static int[] MoveZeroes(int[] arr)
{
return arr.OrderBy(x => x == 0).ToArray();
}
문제 링크 : https://www.codewars.com/kata/52597aa56021e91c93000cb0
반응형