728x90 반응형 HackerRank38 Lonely Integer C# public static int lonelyinteger(List a) { int result = 0; foreach (int num in a) { result ^= num; } return result; } ^= -> XOR 연산으로 Unique value 를 찾을 수 있다는 것이 Key Point 2023. 10. 4. Mini-Max Sum C# class Result { /* * Complete the 'miniMaxSum' function below. * * The function accepts INTEGER_ARRAY arr as parameter. */ public static void miniMaxSum(List arr) { arr.Sort(); long minSum = arr.Take(4).Sum(); long maxSum = arr.Skip(1).Take(4).Sum(); Console.WriteLine($"{minSum} {maxSum}"); } } 2023. 10. 4. Plus Minus C# class Result { /* * Complete the 'plusMinus' function below. * * The function accepts INTEGER_ARRAY arr as parameter. */ public static void plusMinus(int total,List arr) { int pos=0,zero=0,neg=0; foreach(int i in arr){ if(i>0){ pos++; }else if(i==0){ zero++; }else{ neg++; } } Console.WriteLine("{0:.000000}",(double)pos/(double)total); Console.WriteLine("{0:.000000}",(double)neg/(double)total); C.. 2023. 10. 4. 이전 1 ··· 3 4 5 6 다음 728x90 반응형