You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
Constraints:
ALSO CHECK: Other LeetCode Solutions in Java
-K Himaanshu Shuklaa..
Constraints:
- 2 < = coordinates.length <= 1000
- coordinates[i].length == 2
- -10 ^ 4 < = coordinates[i][0], coordinates[i][1] < = 10^4
- coordinates contains no duplicate point.
Java Solution
Algorithm:
Points (x1,y1), (x2,y2) and (x3, y3) are in straight line, if the slope between (x1,y1) and (x2,y2) is equal to the slope between (x2,y2) and (x3, y3).
slope between (x1,y1) and (x2,y2)=(y2-y1)/(x2-x1)
Algorithm:
Points (x1,y1), (x2,y2) and (x3, y3) are in straight line, if the slope between (x1,y1) and (x2,y2) is equal to the slope between (x2,y2) and (x3, y3).
slope between (x1,y1) and (x2,y2)=(y2-y1)/(x2-x1)
ALSO CHECK: Other LeetCode Solutions in Java
-K Himaanshu Shuklaa..
No comments:
Post a Comment