Pages

May 08, 2020

#LeetCode:Check If It Is a Straight Line

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:
  • 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)



ALSO CHECKOther LeetCode Solutions in Java

-K Himaanshu Shuklaa..

No comments:

Post a Comment