当前位置:网站首页>Daily question -1232 Dotted line
Daily question -1232 Dotted line
2022-06-09 11:00:00 【Programmed ape without hair loss 2】
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 .
Example 1:
Input :coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
Output :true
Example 2:

Input :coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
Output :false
Tips :
2 <= coordinates.length <= 1000
coordinates[i].length == 2
-10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
coordinates There are no repeating points in
java Code :
class Solution {
public boolean checkStraightLine(int[][] coordinates) {
/*
* General style :Ax+By+C=0(AB≠0)
* Two point formula :(y-y1)/(x-x1)=(y-y2)/(x-x2) ( Straight line crossing point (x1,y1),(x2,y2))
*/
// The fixed point here is coordinates[0], and coordinates[n-1]
// To avoid Division , Here we use “ The product of two inner terms is equal to the product of two outer terms ” Calculation
int n = coordinates.length;
for(int i = 1; i < n-1; ++i)
{
if(
(coordinates[i][0] - coordinates[0][0])* /* (x-x1)*(y-y2) */
(coordinates[i][1] - coordinates[n-1][1])
!=
(coordinates[i][1] - coordinates[0][1])* /* (y-y1)*(x-x2) */
(coordinates[i][0] - coordinates[n-1][0])
) return false;
}
return true;
}
}
边栏推荐
- 中信建投是安全的吗
- 线程池的实现
- 多线程系列之基本概念
- Configurationmanager pose flash
- [PHP] brief description and relevant examples of the special class trail for code reuse
- 复杂嵌套的对象池(2)——管理单个实例对象的对象池
- Learning fuzzy from SQL injection to bypass the latest safe dog WAF
- merge sort
- InfoQ geek media's 15th anniversary solicitation 𞓜 migration of Eureka to Nacos: dual registration and dual subscription model
- Thirty four - sklearn classifies text emotions according to samples
猜你喜欢

Thirty eight JS tried fractal graphics on canvas (II) tried mountain building, painted mountains and the basis of angular geometry

error NU1202: Package Volo.Abp.Cli 5.2.1 is not compatible with netcoreapp3.1

How to pass the MySQL database header song training task stored procedure?

肆拾伍- 正则表达式 (?=pattern) 以及 (?!pattern)

Thirty one - the number of mongodb links in nodejs simple proxy pool (combined) exploded

开发一个软件应用程序需要多少钱?

C语言与Lua的交互(实践二)

叁拾贰- NodeJS简单代理池(有完没完?) 之 SuperAgent 使用代理不是 Timeout 的 Timeout

三拾壹- NodeJS簡單代理池(合) 之 MongoDB 鏈接數爆炸了

叁拾柒- JS 在 Canvas 上尝试分形图形 (一) 画了一个普通箱子图
随机推荐
Web development exchange, web development example tutorial
你知道多少,深度解析,值得收藏
【图像增强】基于稀疏表示和正则化实现图像增强附matlab代码
NFT市场进入聚合时代,OKALEIDO成BNB Chain上的首个聚合平台
论文阅读 (54):DeepFool: A Simple and Accurate Method to Fool Deep Neural Networks
33 - nodejs simple proxy pool (it's estimated that it's over) the painful experience of using proxy by SuperAgent and the need to be careful
肆拾伍- 正则表达式 (?=pattern) 以及 (?!pattern)
多线程之生产者和消费者模型
人大金仓再次荣获“国家鼓励的重点软件企业”认定
Dotnet core can also coordinate distributed transactions!
NFT market has entered the era of aggregation, and okaleido has become the first aggregation platform on BNB chain
Using source tree to delete remote and local warehouses by mistake
Jincang of the National People's Congress won the recognition of "key software enterprises encouraged by the state" again
Micronet: image recognition with very low flop
Forty five - regular expressions (? =pattern) and (?! pattern)
error NU1202: Package Volo.Abp.Cli 5.2.1 is not compatible with netcoreapp3.1
Thirty four - sklearn classifies text emotions according to samples
软件那些事
今日停更
Is CSC safe