/* * function Point(a, b){ * this.x = a || 0; * this.y = b || 0; * } */ /** * * @param points Point类一维数组 * @return int整型 */ function maxPoints( points ) { // write code here let res = 0; let len = points.length; if(len < 3){ return len; } for(let i=1;i<len;i++){ let count = 0; let a = points[i].x; let b = points[i].y; let xx = a - points[i-1].x; let yy = b - points[i-1].y; if( xx === 0 && yy === 0 ){ for(let j=0;j<len;j++){ if(points[j].x === a && points[j].y === b){ count+=1; } } } else{ for(let j=0;j<len;j++){ if((points[j].x -a) * yy === (points[j].y - b) * xx){ count+=1; } } } res = Math.max(res,count) } return res } module.exports = { maxPoints : maxPoints };