标签:function highlight UNC bsp int point class func jit
给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上。
function maxPoints(points) { if(points.length == 1){ return 1 } let number = 0 for(let i = 0;i < points.length-1;i++){ let item = points[i] for(let j = i+1;j < points.length;j++){ let jItem = points[j] let r,n,num = 0; if(jItem[0] == item[0]){ r = 0 for(let k = 0;k < points.length;k++){ let kItem = points[k] if(kItem[0] == item[0]){ num++ } } }else if(jItem[1] == item[1]){ for(let k = 0;k < points.length;k++){ let kItem = points[k] if(kItem[1] == item[1]){ num++ } } }else{ r = (jItem[1]-item[1]) / (jItem[0]-item[0]) n = ((jItem[1]+item[1]) - ((jItem[0]+item[0]) * r))/2 for(let k = 0;k < points.length;k++){ let kItem = points[k] if(kItem[1] == (kItem[0] * r + n)){ num++ } } } if(num > number){ number = num } } } return number }
标签:function highlight UNC bsp int point class func jit
原文地址:https://www.cnblogs.com/zhenjianyu/p/13155165.html