当前位置:网站首页>Maximum number of points on the line ----- hash table solution
Maximum number of points on the line ----- hash table solution
2022-06-11 05:21:00 【Food can be very delicious】
Title Description
Give you an array points , among points[i] = [xi, yi] Express X-Y A point on the plane . Find out how many points are in the same line at most .
Example 1:
Input :points = [[1,1],[2,2],[3,3]]
Output :3
Example 2:
Tips :
Input :points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output :4
1 <= points.length <= 300
points[i].length == 2
-104 <= xi, yi <= 104
points All the points in Different from each other
Their thinking
Let's start with a question , What are the conditions on the same line ?
The slope of the straight line formed by each point on the straight line is equal
Let's do a double-layer traversal , The outer layer traverses the entire point array , The group of points after the inner layer traverses the position of the outer point , By finding the formula for the slope , Build a hash table , Record the number of slope occurrences in the table , After inner layer traversal , Find the slope with the most occurrences , This is the number of points with the largest number of lines headed by the outer point position (+1).
Code
Stick the leetcode Pass code
class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
answer=0
for i in range(len(points)):
temp_dict=dict()
for j in range(i+1,len(points)):
if (points[j][0]-points[i][0])==0:
temp="*"
else:
temp=(points[j][1]-points[i][1])/(points[j][0]-points[i][0])
if temp not in temp_dict:
temp_dict[temp]=1
else:
temp_dict[temp]+=1
if len(temp_dict)!=0:
b=max(temp_dict.values())
answer=max(b,answer)
return answer+1

边栏推荐
- Cascade EF gan: local focus progressive facial expression editing
- Iris dataset - Introduction to machine learning
- (15) Infrared communication
- Topological sorting
- Section II: structural composition characteristics of asphalt pavement (1) structural composition
- Technical dry goods: how to select the most suitable RDMA network card
- WinForm (II) advanced WinForm and use of complex controls
- Titanic rescued - re exploration of data mining (ideas + source code + results)
- Sealem finance builds Web3 decentralized financial platform infrastructure
- wxParse解析iframe播放视频
猜你喜欢

MySQL regularly deletes expired data.

Yolov5 training personal data set summary

如何让灯具智能化,单火、零火智能开关怎么选!
![[NIPS2021]MLP-Mixer: An all-MLP Architecture for Vision](/img/89/66c30ea8d7969fef76785da1627ce5.jpg)
[NIPS2021]MLP-Mixer: An all-MLP Architecture for Vision
![[entry level basics] node basic knowledge summary](/img/91/39aff1ade1f37f54b61a454e32d487.jpg)
[entry level basics] node basic knowledge summary

Apply the intelligent OCR identification technology of Shenzhen Yanchang technology to break through the bottleneck of medical bill identification at one stroke. Efficient claim settlement is not a dr

English digital converter

Huawei equipment configuration MCE

Thesis 𞓜 jointly pre training transformers on unpaired images and text

Inventory | ICLR 2022 migration learning, visual transformer article summary
随机推荐
What is a smart network card? What is the function of the smart network card?
js promise,async,await简单笔记
Yolov5 training personal data set summary
Some details about memory
Zed2 camera calibration -- binocular, IMU, joint calibration
How to apply for free idea with official documents
Opencv learning path (2-2) -- Deep parsing namedwindow function
华为设备配置通过GRE接入虚拟专用网
Tightly coupled laser vision inertial navigation slam system: paper notes_ S2D. 66_ ICRA_ 2021_ LVI-SAM
Sealem Finance打造Web3去中心化金融平台基础设施
27. Remove elements
AAAI2022-ShiftVIT: When Shift Operation Meets Vision Transformer
lower_ Personal understanding of bound function
Section V: Recycling Application of asphalt pavement materials
27、移除元素
Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration
Following the wave of lack of core, Lianrui launched a number of gigabit network card solutions
IOU series (IOU, giou, Diou, CIO)
Reverse thinking: making cartoon photos real
Chapter I: Net architecture (1)