List<Point> list = Arrays.asList(new Point(1, 5), new Point(2, 3), new Point(2, 8), new Point(9, 13)); int sum = list.get(0).y - list.get(0).x,currenty=list.get(0).y; Point pnext; for (int i = 1, len = list.size(); i < len; i++) { pnext = list.get(i); if (currenty >= pnext.y) continue; sum += currenty >= pnext.x ? pnext.y - currenty : pnext.y - pnext.x; currenty = pnext.y; } System.out.println(sum);
算法 计算多个顺序区间的总长
时间: 2024-10-05 02:37:05