当前位置:网站首页>Li Kou daily question - Day 32 -1232 Dotted line
Li Kou daily question - Day 32 -1232 Dotted line
2022-07-01 18:47:00 【Chongyou research Sen】
2022.7.1 Did you brush the questions today ?
subject :
Given an array coordinates , among coordinates[i] = [x, y] , [x, y] The abscissa is x、 Ordinate for y The point of . Please judge , Whether these points belong to the same line in the coordinate system .
analysis :
Here are some two-dimensional arrays , You need to judge whether these two-dimensional arrays are on a straight line , But one thing to pay attention to , If you're going to find out y=kx+b To judge , There will be cases where the denominator is negative when the slope is divided !
Ideas : Using the slope formula
(y1-y0)/(x1-x0)=(yi-y0)/(xi-x0) Prevention and elimination 0, Transformed into a form of multiplication (y1-y0)*(xi-x0)==(x1-x0)*(yi-y0)
analysis :
1. Violent solution
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;
}
};边栏推荐
- Draw drawing process of UI drawing process
- Leetcode-83 删除排序链表中重复的元素
- Introduction to easyclick database
- 为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!
- Bernoulli distribution (a discrete distribution)
- R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
- Memo - about C # generating barcode for goods
- code
- Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
- 540. Single element in ordered array
猜你喜欢

研究了11种实时聊天软件,我发现都具备这些功能…

After studying 11 kinds of real-time chat software, I found that they all have these functions

Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?

Basic concepts of binary tree

540. Single element in ordered array

PCL learning materials

Write an open source, convenient and fast database document query and generation tool with WPF

Mysql database of easyclick

Three.js学习-相机Camera的基本操作(了解向)

Image acquisition and playback of coaxpress high speed camera based on pxie interface
随机推荐
搭建一個通用監控告警平臺,架構上需要有哪些設計
Solution: you can ping others, but others can't ping me
记一次 .NET 差旅管理后台 CPU 爆高分析
Data query language (DQL)
How to find the optimal learning rate
Thread forced join, thread forced join application scenarios
LeetCode 148. Sort linked list
1380. Lucky number in matrix / 1672 Total assets of the richest customers
540. Single element in ordered array
Static timing analysis (STA) in ic/fpga design
Popular science: what does it mean to enter the kernel state?
必看,时间序列分析
Leetcode-83 删除排序链表中重复的元素
Memo - about C # generating barcode
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
Salesmartly has some tricks for Facebook chat!
The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
12. Design of power divider for ads usage record
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)