码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode max-points-on-a-line

时间:2016-09-01 02:03:04      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

/*
表示很无语,为什么同样的点还要计算在里面,导致一直没有AC
 
*/
/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */ class Solution { public: int maxPoints(vector<Point> &points) { int len = points.size(); if(len <= 2) return len; int ans = 2; for(int i = 0 ; i < len ; i ++){ int du = 0; for(int j = i + 1 ; j < len ; j ++){ int cnt = 1; if(points[j].x == points[i].x && points[j].y == points[i].y){ du ++; ans = max(cnt+du , ans); continue; } cnt ++; for(int k = j + 1 ; k < len ; k ++){ int x = (points[k].x - points[i].x)*(points[k].y - points[j].y); int y = (points[k].x - points[j].x)*(points[k].y - points[i].y); if(x == y) cnt ++; } ans = max(cnt+du , ans); } } return ans; } };

  

leetcode max-points-on-a-line

标签:

原文地址:http://www.cnblogs.com/castlehappiness/p/5828148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!