当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- Sanfeng cloud 0215 I often use
- Using OpenSSL encryption to rebound shell traffic
- 540. Single element in ordered array / 1684 Count the number of consistent strings
- Is Alipay wallet convenient to use?
- Depth first search - DFS (burst search)
- Nielseniq found that 60% of the re launched products had poor returns
- How to find the optimal learning rate
- Flex layout
- ArrayList扩容详解
猜你喜欢

12种数据量纲化处理方式

A wonderful time to buy and sell stocks

How to retrieve the password for opening Excel files

3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT

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

信度系数低怎么办?信度系数具体怎么算?

Computer network interview assault

Leetcode203 移除链表元素

Depth first search - DFS (burst search)

Yuancosmos game farmersworld farmers world - core content of the second conference in China!
随机推荐
The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
期货账户的资金安全吗?怎么开户?
MySQL + JSON = King fried
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
How to find customers for investment attraction in industrial parks
Vue uses keep alive to cache page optimization projects
On the language internationalization of Yongzhong Office
Data query language (DQL)
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Leetcode-160相交链表
SPIE Western optoelectronics exhibition returned offline and successfully held a science and engineering event
Roll out! Enlightenment!
網上股票開戶安全嗎?是否可靠?
MySQL connection tools
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
Operating system interview assault
Small exercise -- subnet division and summary
Opencv map reading test -- error resolution
js如何将带有分割符的字符串转化成一个n维数组
How to find the optimal learning rate