일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Protocol
- Convert Sorted List to Binary Search Tree
- Class
- Substring with Concatenation of All Words
- Regular Expression
- 컴퓨터의 구조
- t1
- 315. Count of Smaller Numbers After Self
- 파이썬
- data science
- Python Code
- 시바견
- 715. Range Module
- 30. Substring with Concatenation of All Words
- 운영체제
- shiba
- Generator
- Python
- Decorator
- Python Implementation
- concurrency
- kaggle
- LeetCode
- DWG
- iterator
- 프로그래머스
- 43. Multiply Strings
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- attribute
Archives
- Today
- Total
Scribbling
LeetCode: 149. Max Points on a Line 본문
직선 찾기 문제
핵심은...
1) 실수 처리를 회피하기 위한 slope의 처리
2) map의 활용
from collections import defaultdict
import math
class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
ret = 1
for i in range(len(points)):
p1 = points[i]
lineDict = defaultdict(lambda: 1)
for j in range(len(points)):
if i == j:
continue
p2 = points[j]
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
if dx == 0:
slope = (0, 1)
elif dy == 0:
slope = (1, 0)
else:
gcd = math.gcd(dy, dx)
slope = (dx // gcd, dy // gcd)
lineDict[slope] += 1
ret = max(ret, lineDict[slope])
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 1329. Sort the Matrix Diagonally (0) | 2021.11.24 |
---|---|
LeetCode: 1466. Reorder Routes to Make All Paths Lead to the City Zero (0) | 2021.11.23 |
LeetCode: 143. Reorder List (0) | 2021.11.22 |
LeetCode: 140. Word Break II (0) | 2021.11.22 |
LeetCode: 139. Word Break (0) | 2021.11.19 |