当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Introduction to easyclick database
- Equipment simulation and deduction training system software
- 期货账户的资金安全吗?怎么开户?
- [Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- APK签名流程介绍[通俗易懂]
- Nielseniq found that 60% of the re launched products had poor returns
- (6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
- 网上股票开户安全吗?是否可靠?
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
猜你喜欢

Leetcode-128 最长连续序列

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

Leetcode-160相交链表

Extract the compressed package file and retrieve the password

Mujoco model learning record

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

The method of real-time tracking the current price of London Silver

Distributed task queue: Celery usage record

Localization through custom services in the shuttle application

Classpath classpath
随机推荐
540. Single element in ordered array / 1684 Count the number of consistent strings
PTA year of birth
Fix the black screen caused by iPhone system failure
Find all missing numbers in the array
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
Search 2D matrix 2
Mujoco model learning record
What impact will multinational encryption regulation bring to the market in 2022
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
MySQL connection tools
Distributed task queue: Celery usage record
LeetCode 148. Sort linked list
[noip2015] jumping stone
Blue Bridge Cup real problem: word analysis
How to retrieve the password for opening Excel files
To improve the efficiency of office collaboration, trackup may be the best choice
Three dimensional anti-terrorism Simulation Drill deduction training system software
Opencv map reading test -- error resolution
[acnoi2022] color ball
Implementation of converting PCM file to WAV