当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Yolov5 practice: teach object detection by hand
- GAMES202作业0-环境搭建过程&解决遇到的问题
- 必看,时间序列分析
- 540. Single element in ordered array
- Introduction to easyclick database
- Localization through custom services in the shuttle application
- Explain in detail the process of realizing Chinese text classification by CNN
- (6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- Search 2D matrix 2
猜你喜欢

2、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》启动并运行您的本地环境

Mysql database of easyclick

Find all missing numbers in the array

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

Static timing analysis (STA) in ic/fpga design

Sum of three numbers

Oracle TRUNC function processing date format

Domestic spot silver should be understood

How to find the optimal learning rate

Operation of cmake under win
随机推荐
Bug of QQ browser article comment: the commentator is wrong
Talk about the favorite tools used by project managers
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
Classpath classpath
SPIE Western optoelectronics exhibition returned offline and successfully held a science and engineering event
Equipment simulation and deduction training system software
Relational database management system of easyclick
golang中的select详解
[noip2015] jumping stone
2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
Calculation of intersection of two line segments
How to retrieve the password for opening Excel files
LeetCode 148. Sort linked list
1380. Lucky number in matrix / 1672 Total assets of the richest customers
At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
Apk signature process introduction [easy to understand]
APK签名流程介绍[通俗易懂]
How to change guns for 2D characters
期货账户的资金安全吗?怎么开户?
Leetcode-141环形链表