기본 틀 :
using System;
class Solution
{
public int solution(int[] nums)
{
int answer = -1;
// [실행] 버튼을 누르면 출력 값을 볼 수 있습니다.
System.Console.WriteLine("Hello C#");
return answer;
}
}
문제를 보고 3개의 수의 합이 중복이 없어야 하는줄 알고
HashSet으로 문제를 풀었다가
23점이 나와서 깜짝 놀랐다...
(문제를 잘 보면 nums에 중복된 숫자가 들어있지 않다는건데...)
using System;
using static System.Math;
using System.Collections.Generic;
class Solution
{
public int solution(int[] nums)
{
List<int> list = new List<int>();
for(int i = 0; i < nums.Length - 2; i++)
{
for(int j = i + 1; j < nums.Length - 1; j++)
{
for(int k = j + 1; k < nums.Length; k++)
{
list.Add(nums[i] + nums[j] + nums[k]);
}
}
}
int count = 0;
for(int i = 0; i < list.Count; i++)
{
bool check = true;
for(int j = 2; j <= (int)Math.Sqrt(list[i]); j++)
{
if(list[i] % j == 0)
{
check = false;
break;
}
}
if(check) count++;
}
return count;
}
}