Here you can find the source of removeDuplicatesInPath(int[][] path)
public static int[][] removeDuplicatesInPath(int[][] path)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { public static int[][] removeDuplicatesInPath(int[][] path) { if (path.length <= 2) return path; int[][] newPath = new int[path.length][]; int index = 0; newPath[0] = path[0];//from ww w . j a v a 2 s.c o m for (int i = 1; i < path.length - 1; ++i) { if (isCollinear(path[i][0], path[i][1], path[i + 1][0], path[i + 1][1], newPath[index][0], newPath[index][1])) { // skip } else { index++; newPath[index] = path[i]; } } index++; newPath[index] = path[path.length - 1]; return Arrays.copyOf(newPath, index + 1); } private static boolean isCollinear(int x1, int y1, int x2, int y2, int x3, int y3) { return (y3 - y1) * (x2 - x1) == (x3 - x1) * (y2 - y1); } }