| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- 파이썬
- 시바견
- Python
- shiba
- kaggle
- 30. Substring with Concatenation of All Words
- Regular Expression
- Generator
- attribute
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- Protocol
- 밴픽
- 프로그래머스
- t1
- 715. Range Module
- Class
- 43. Multiply Strings
- concurrency
- 컴퓨터의 구조
- DWG
- Python Code
- Decorator
- data science
- LeetCode
- Convert Sorted List to Binary Search Tree
- iterator
- 운영체제
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 |