#1232

Check If It Is a Straight Line

pupil · 490 · lc easy +27 · verified · 40% accepted · 2,699 likes · top 19%

Description

You are given an array of 2D coordinates, where coordinates[i] = [x, y] represents a point. Determine whether all the given points lie on the same straight line in the XY plane.

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

Code

1
2
3