当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Distributed task queue: Celery usage record
- 主成分之综合竞争力案例分析
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- Mysql database of easyclick
- Yolov5 practice: teach object detection by hand
- Sanfeng cloud 0215 I often use
- 3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
- 创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
- ArrayList扩容详解
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
猜你喜欢

Oracle TRUNC function processing date format

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

Leetcode-160相交链表

创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)

t10_ Adapting to Market Participantsand Conditions
![[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out](/img/f3/20b73f3545cdd17b9fbc52bf493ab4.jpg)
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

Apache iceberg source code analysis: schema evolution

Classpath classpath

1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
随机推荐
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Apk signature process introduction [easy to understand]
Slider verification code identification gadget display
Terms related to K line
Review Net 20th anniversary development and 51aspx growth
Subnet division and summary
Yolov5 practice: teach object detection by hand
C# SelfHost WebAPI (2)
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
Single element of an ordered array
Bug of QQ browser article comment: the commentator is wrong
Mujoco model learning record
js如何将带有分割符的字符串转化成一个n维数组
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Three dimensional anti-terrorism Simulation Drill deduction training system software
Search 2D matrix 2
Computer network interview assault
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
Three.js学习-相机Camera的基本操作(了解向)