does OJ support Python import collections Counter? (yes)
can you help me look at my code at https://oj.leetcode.com/submissions/detail/8630902/ ?
class Solution: # @param points, a list of Points # @return an integer def maxPoints(self, points): def eval(a, b): if a.x-b.x == 0 and a.y-b.y == 0: return 'identical' if a.x-b.x == 0: return float("inf") return (float(a.y-b.y)/(a.x-b.x)) if len(points) == 0: return 0 slopematrix = [[eval(a,b) for b in points] for a in points] MaxPoints = 0 for idx, slopes in enumerate(slopematrix): counter = collections.Counter(slopes) for i in counter.most_common(): slope = i count = i if slope == 'identical' and count > MaxPoints: MaxPoints = count count = i + counter['identical'] if slope != 'identical' and slope != float("inf") and count > MaxPoints: MaxPoints = count return MaxPoints
Yes, we imported
collections. So, please use 'Counter' as below:
cnt = collections.Counter()
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.