当前位置:网站首页>力扣每日一题-第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;
}
};
边栏推荐
- Operation of cmake under win
- Classpath classpath
- Nielseniq found that 60% of the re launched products had poor returns
- Static timing analysis (STA) in ic/fpga design
- Three.js学习-相机Camera的基本操作(了解向)
- Blue Bridge Cup real topic: the shortest circuit
- From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
- Roll out! Enlightenment!
- PCL learning materials
- Redis master-slave realizes 10 second check and recovery
猜你喜欢
必看,时间序列分析
Static timing analysis (STA) in ic/fpga design
Extract the compressed package file and retrieve the password
关于企业中台规划和 IT 架构微服务转型
Samba basic usage
How to find the optimal learning rate
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Leetcode-160相交链表
Cloud computing - make learning easier
Classpath classpath
随机推荐
What is web application security testing technology?
[acnoi2022] color ball
540. Single element in ordered array
Localization through custom services in the shuttle application
期货账户的资金安全吗?怎么开户?
Vue uses keep alive to cache page optimization projects
What are the legal risks of NFT brought by stars such as curry and O'Neill?
Sum of three numbers
Operating system interview assault
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Apk signature process introduction [easy to understand]
How to manage 1000 anchors by one person?
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
Distributed task queue: Celery usage record
t10_ Adapting to Market Participantsand Conditions
GAMES202作业0-环境搭建过程&解决遇到的问题
信度系数低怎么办?信度系数具体怎么算?
Database - MySQL advanced SQL statement (I)
Explain in detail the process of realizing Chinese text classification by CNN