当前位置:网站首页>力扣每日一题-第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;
}
};
边栏推荐
- How to manage 1000 anchors by one person?
- Search 2D matrix 2
- Happy new year | 202112 monthly summary
- Domestic spot silver should be understood
- [CF559E]Gerald and Path
- 網上股票開戶安全嗎?是否可靠?
- Computer network interview assault
- Three dimensional anti-terrorism Simulation Drill deduction training system software
- 每周推荐短视频:警惕“现象”与“问题”相互混淆
- Flex layout
猜你喜欢
Relational database management system of easyclick
Sum of three numbers
Distributed task queue: Celery usage record
Classpath classpath
12种数据量纲化处理方式
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
Basic concepts of binary tree
A wonderful time to buy and sell stocks
Leetcode203 移除链表元素
随机推荐
Subnet division and summary
PCL learning materials
信度系数低怎么办?信度系数具体怎么算?
Rust language - cargo, crates io
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
JS how to convert a string with a delimiter into an n-dimensional array
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
Basic usage of shell script
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
Three dimensional anti-terrorism Simulation Drill deduction training system software
Localization through custom services in the shuttle application
1380. Lucky number in matrix / 1672 Total assets of the richest customers
网上股票开户安全吗?是否可靠?
Convert the robot's URDF file to mujoco model
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Sanfeng cloud 0215 I often use
How to change guns for 2D characters
What impact will multinational encryption regulation bring to the market in 2022
Oracle TRUNC function processing date format
Redis主从实现10秒检查与恢复