当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- ZABBIX alarm execute remote command
- Static timing analysis (STA) in ic/fpga design
- Equipment simulation and deduction training system software
- Single element of an ordered array
- (6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
- Extract the compressed package file and retrieve the password
- A wonderful time to buy and sell stocks
- Apache iceberg source code analysis: schema evolution
- Fix the black screen caused by iPhone system failure
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
猜你喜欢

MySQL connection tools

1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT

Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking

Sum of three numbers

From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl

How to retrieve the password for opening Excel files

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

Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?

Samba basic usage

Explain in detail the process of realizing Chinese text classification by CNN
随机推荐
Slider verification code identification gadget display
Basic concepts of binary tree
Localization through custom services in the shuttle application
Equipment simulation and deduction training system software
golang中的select详解
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Samba basic usage
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
Flex layout
At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
Oracle TRUNC function processing date format
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
ZABBIX alarm execute remote command
Zabbix报警执行远程命令
Blue Bridge Cup real problem: word analysis
Record 3 - the state machine realizes key control and measures the number of external pulses
信度系数低怎么办?信度系数具体怎么算?
What is web application security testing technology?
Depth first search - DFS (burst search)
Win10+vs2019 Community Edition compiling OpenSSL