成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

leetcode-149-Max Points on a Line

darcrand / 2125人閱讀

"""
Given n points on a 2D plane,
find the maximum number of points that lie on the same straight line.

"""

from decimal import Decimal

# Definition for a point.
class Point:
    def __init__(self, a=0, b=0):
        self.x = a
        self.y = b

class Solution:
    def maxPoints(self, points):
        """
        :type points: List[Point]
        :rtype: int
        """
        if not points:
            return 0
        # xs=[point.x for point in points]
        # ys=[point.y for point in points]
        length=len(points)
        if length==1:
            return 1
        counter=0
        for ip in range(length-1):

            kdict={"i":1}
            same=0
            for jp in range(ip+1,length):
                if points[jp].x==points[ip].x and points[ip].y==points[jp].y:
                    same+=1
                elif points[jp].x==points[ip].x:
                    kdict["i"]+=1
                else:
                    k=Decimal(points[jp].y-points[ip].y*Decimal(1.0))/Decimal(points[jp].x-points[ip].x)
                    print(k)
                    if k not in kdict.keys():
                        kdict[k]=2
                    else:
                        kdict[k]+=1

            counter=max(counter,max(kdict.values())+same)
        # print(counter)
        return counter
if __name__=="__main__":
    st=Solution()
    points=[Point(i,j) for i in range(9) for j in range(3,12)]
    points=[Point(1,2),Point(1,2),Point(1,2),Point(3,6),Point(2,4),Point(4,8),Point(5,10),]
    # points=[Point(0,0)]
    # points=[Point(0,0),Point(1,0)]

    points=[Point(0,0),Point(1,1),Point(1,-1)]
    points=[Point(0,0),Point(94911151,94911150),Point(94911152,94911151)]

    out=st.maxPoints(points)
    print(out)
    float```

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/44560.html

相關(guān)文章

  • [LintCode] Max Points on a Line

    摘要:兩次循環(huán)對中第個和第個進行比較設(shè)置重復(fù)點數(shù),相同斜率點數(shù)。內(nèi)部循環(huán)每次結(jié)束后更新和點相同斜率的點的最大數(shù)目。外部循環(huán)每次更新為之前結(jié)果和本次循環(huán)所得的較大值。重點一以一個點為參照求其他點連線的斜率,不需要計算斜率。 Problem Given n points on a 2D plane, find the maximum number of points that lie on th...

    bingo 評論0 收藏0
  • [Leetcode] Max Points on a Line 線上最大點數(shù)

    摘要:哈希表復(fù)雜度時間空間思路一個點加一個斜率,就可以唯一的確定一條直線。這里,我們用哈希表,以斜率為,記錄有多少重復(fù)直線。注意哈希表的為,但是可以有正和負的,而且不一樣。 Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the same stra...

    ernest.wang 評論0 收藏0
  • [Leetcode] Max Points on a Line 直線上最多的點數(shù)

    摘要:分子分母同時除以他們的最大公約數(shù)即可得到最簡分數(shù),一般求的是兩個正整數(shù)的。這道題和有可能是,分別表示與軸或軸平行的斜率注意不能同時為表示同一個點沒有意義,所以這道題我們規(guī)定取值范圍。 Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the s...

    張憲坤 評論0 收藏0
  • LeetCode 4

    摘要:這個題的思路就是找數(shù)組里的兩個點,用這兩個點來做一條直線,然后看數(shù)組里的點都在直線上不,我用的是兩點式,需要考慮兩個點或坐標相同的特殊情況。 Max Points on a Line https://oj.leetcode.com/problems/max-points-on-a-line/ Given n points on a 2D plane, find the maximu...

    zhkai 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<