注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
线段重合问题, tripadvisor店面全部代码
import java.io.*; import java.util.*; import org.junit.*; import org.junit.runner.*;
/** * Write a function that can take an arbitrary number of rental * car reservations that returns the minimum number of cars * required to support these reservations. For instance: */ public class Solution { /** * Example 1 * Reservation 1: --- * Reservation 2: ---- * Reservation 3: --- * requires 1 cars, and */ @Test public void testExample1() { // requires 1 car List<Reservation> example1 = Arrays.asList( new Reservation[] { new Reservation(1000,1100), new Reservation(1100,1200), new Reservation(1300,1400) } );
Assert.assertEquals(1, minCars(example1)); }
/** * Example 2 * Reservation 1: -- * Reservation 2: --- * Reservation 3: -- * Reservation 4: - total.add(new Pair(r.getPickupTime(), true)); total.add(new Pair(r.getReturnTime(), false)); } Collections.sort(total, (p1, p2) -> (int)(p1.time - p2.time)); for (Pair p: total) { if (p.isStart) { cnt++; if (cnt > max) max = cnt; } else cnt--; } return max; }
public static void main(String[] args) { JUnitCore.main("Solution"); } }
|