Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created April 30, 2020 04:45
Show Gist options
  • Save DongguemYoo/cda22f18cf62858974db81bc6a873b4e to your computer and use it in GitHub Desktop.
Save DongguemYoo/cda22f18cf62858974db81bc6a873b4e to your computer and use it in GitHub Desktop.
코딩테스트 연습 나누어떨어지는 숫자배열
using System.Collections.Generic; // List사용하기 위해 필요
using System; //Array 사용하기 위해 필요
public int[] solution(int[] arr, int divisor)
{
int[] answer = new int[] { };
List<int> a = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % divisor == 0)
a.Add(arr[i]);
}
if (a.Count == 0)
return answer = new int[1] { -1};
answer = a.ToArray();
Array.Sort(answer); //Array.Sort도 있지만 List.Sort도 있다
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment