[Solved] Leetcode 2152, minimum Number of Lines to Cover Points. Fail at when x-axis is same [closed]


The problem is in this line:

if(p2 !== p1) {

In your use of the function, p1 and p2 are arrays with x and y coordinates. Such a comparison is only true when p1 and p2 are the same array reference. This is never the case in your use cases.

You need this (as is also the case in the Python version):

if(p2[0] !== p1[0]) {

solved Leetcode 2152, minimum Number of Lines to Cover Points. Fail at when x-axis is same [closed]