当前位置:网站首页>力扣每日一题-第32天-1232. 缀点成线
力扣每日一题-第32天-1232. 缀点成线
2022-07-01 18:33:00 【重邮研究森】
2022.7.1今天你刷题了吗?
题目:
给定一个数组 coordinates ,其中 coordinates[i] = [x, y] , [x, y] 表示横坐标为 x、纵坐标为 y 的点。请你来判断,这些点是否在该坐标系中属于同一条直线上。
分析:
给你一些二维数组,你需要判断这些二维数组是不是在一个直线上面,但是要注意一个点,如果你打算求出y=kx+b来判断,会有斜率相除时分母为负数情况!
思路:利用斜率公式
(y1-y0)/(x1-x0)=(yi-y0)/(xi-x0) 防止除0,变换成相乘的形式 (y1-y0)*(xi-x0)==(x1-x0)*(yi-y0)
解析:
1.暴力求解
class Solution {
public:
bool checkStraightLine(vector<vector<int>>& coordinates) {
for (auto i = 2; i < coordinates.size(); i++)
{
if ((coordinates[1][1]-coordinates[0][1])*(coordinates[i][0]-coordinates[0][0])!=(coordinates[i][1]-coordinates[0][1])*(coordinates[1][0]-coordinates[0][0]))
{
return false;
}
}
return true;
}
};边栏推荐
- Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
- 网上股票开户安全吗?是否可靠?
- On the language internationalization of Yongzhong Office
- Explain in detail the process of realizing Chinese text classification by CNN
- 2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
- Develop those things: add playback address authentication to easycvr platform
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- Blue Bridge Cup real topic: the shortest circuit
- Yuancosmos game farmersworld farmers world - core content of the second conference in China!
- Draw drawing process of UI drawing process
猜你喜欢

Leetcode203 移除链表元素

Record 3 - the state machine realizes key control and measures the number of external pulses

The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup

How to manage 1000 anchors by one person?

Review Net 20th anniversary development and 51aspx growth

2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers

A wonderful time to buy and sell stocks

Mujoco's biped robot Darwin model

Definition of rotation axis in mujoco

Samba basic usage
随机推荐
每周推荐短视频:警惕“现象”与“问题”相互混淆
Slider verification code identification gadget display
Localization through custom services in the shuttle application
Session layer of csframework, server and client (1)
Operation of cmake under win
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
Leetcode-160相交链表
Roll out! Enlightenment!
Happy new year | 202112 monthly summary
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
Thread forced join, thread forced join application scenarios
Equipment simulation and deduction training system software
Search 2D matrix 2
Is online stock account opening safe? Is it reliable?
Database - MySQL advanced SQL statement (I)
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
Apk signature process introduction [easy to understand]
LeetCode 148. Sort linked list
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #