Algorithms and Data Structures/Coding Practices

AlgoExpert Class Photos

brightlightkim 2022. 7. 13. 10:38

import java.util.*;

class Program {

  public boolean classPhotos(
      ArrayList<Integer> redShirtHeights, ArrayList<Integer> blueShirtHeights) {
    Collections.sort(redShirtHeights);
    Collections.sort(blueShirtHeights);
    int diff = redShirtHeights.get(0) - blueShirtHeights.get(0);
    for (int i = 0; i < redShirtHeights.size(); i++){
      if ((redShirtHeights.get(i) - blueShirtHeights.get(i))*diff <= 0){
        return false;
      } 
    }
    return true;
  }
}

'Algorithms and Data Structures > Coding Practices' 카테고리의 다른 글

AlgoExpert Tandem Bike  (0) 2022.07.14
LeetCode 74. Search a 2D Matrix  (0) 2022.07.13
AlgoExpert Minimum Waiting Time  (0) 2022.07.12
AlgoExpert Depth First Search (DFS)  (0) 2022.07.12
AlgoExpert Node Depths  (0) 2022.07.12