import java.util.*;
class Program {
public int tandemBicycle(int[] redShirtSpeeds, int[] blueShirtSpeeds, boolean fastest) {
Arrays.sort(redShirtSpeeds);
Arrays.sort(blueShirtSpeeds);
int sum = 0;
for (int i = 0; i < redShirtSpeeds.length; i++){
if (fastest){
sum += Math.max(redShirtSpeeds[i], blueShirtSpeeds[redShirtSpeeds.length - 1 - i]);
} else {
sum += Math.max(redShirtSpeeds[i], blueShirtSpeeds[i]);
}
}
return sum;
}
}
'Algorithms and Data Structures > Coding Practices' 카테고리의 다른 글
LeetCode 15. 3Sums (0) | 2022.07.14 |
---|---|
AlgoExpert Remove Duplicates from LinkedList (0) | 2022.07.14 |
LeetCode 74. Search a 2D Matrix (0) | 2022.07.13 |
AlgoExpert Class Photos (0) | 2022.07.13 |
AlgoExpert Minimum Waiting Time (0) | 2022.07.12 |