提交记录
提交记录 11 / 64 个通过测试用例 状态:解答错误 最后执行的输入:6 [[0,1],[2,3],[4,5]]
代码(Python3)
from typing import List
class Solution:
lines = []
class PointLine:
def __init__(self, p1, p2):
self.point1 = p1
self.point2 = p2
pass
def countPairs(self, n: int, edges: List[List[int]]) -> int:
count = 0
already = set()
for x in edges:
self.lines.append(self.PointLine(x[0], x[1]))
for x in range(n):
for y in range(n):
if x == y or already >= {x.__str__() + "|" + y.__str__(), }:
continue
already.add(x.__str__() + "|" + y.__str__())
already.add(y.__str__() + "|" + x.__str__())
if not self.find_way(x, y):
count += 1
return count
def find_way(self, p1, p2) -> bool:
for n in self.lines:
if ((n.point1 == p1 and n.point2 == p2)
or
(n.point1 == p2 and n.point2 == p1)):
return True
return False
print(Solution().countPairs(6, [[0, 1], [2, 3], [4, 5]]))
知道写的不是很优雅,这两天才学的 可是这是啥情况...
1
Moonkin 2022-06-26 21:56:39 +08:00
我也遇到过。。
|