글
프로그래머스 C# 최솟값 구하기(배열 곱의 최솟값, Reverse, Sort of Array)
프로그래밍
2023. 1. 23. 21:38
728x90
SMALL
using System;
public class Solution {
public int solution(int[] A, int[] B) {
int answer = 0;
Array.Sort(A);
Array.Sort(B);
Array.Reverse(B);
// 한쪽은 작은 수부터 정렬하고 다른 쪽은 큰수 부터 정렬해서 곱셈 한다.
for(int i=0; i<A.Length; i++)
{
answer += A[i]*B[i];
}
return answer;
}
}
728x90
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# x만큼 간격이 있는 n개의 숫자(using System.Collections.Generic, List.Add) (0) | 2023.01.23 |
---|---|
프로그래머스 C# 행렬의 덧셈(GetLength, 이중 배열 덧셈) (0) | 2023.01.23 |
프로그래머스 C# 피보나치 수(점화식) (0) | 2023.01.23 |
프로그래머스 C# 하샤드 수(0 예외 처리) (0) | 2023.01.23 |
프로그래머스 C# 콜라츠 추측(while, long, 1일 때 예외처리) 쉬움 (0) | 2023.01.23 |