#LeetCode (May LeetCoding Challenge):Check If It Is a Straight Line

Himaanshu Shukla
1 min readMay 8, 2020

--

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⁴ <= coordinates[i][0], coordinates[i][1] <= 10⁴
coordinates contains no duplicate point.

GIT URL: Java Solution of Leet Code’s Cousins in Binary Tree problem

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)

Java Solution

--

--

Himaanshu Shukla

Software Engineer | Certified Scrum Master | Angel Therapy Practitioner| Light Worker| Empath | Buy me a coffee https://ko-fi.com/greekykhs |Blogger