View on GitHub

leetcode-diaries

A journal to record the solution of the various Leetcode problems solved over the course of time.

Check If It Is a Straight Line

Leetcode problem 1232; Difficulty: Easy

Problem Statement

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:

Example 1:

image

Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]

Output: true

Example 2:

image

Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]

Output: false

Submitted Solution

The implemented solution received the following rating on Leetcode:

image