Skip to content
LC-1232 Easy LeetCode

1232. Check If It Is a Straight Line

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 40% Topics: Array, Math, Geometry
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def checkStraightLine(self, coordinates):
        """
        :type coordinates: List[List[int]]
        :rtype: bool
        """
        i, j = coordinates[:2]
        return all(i[0] * j[1] - j[0] * i[1] +
                   j[0] * k[1] - k[0] * j[1] +
                   k[0] * i[1] - i[0] * k[1] == 0
                   for k in coordinates)

Solution from kamyu104/LeetCode-Solutions · MIT