DEV Community

Animesh Kumar
Animesh Kumar

Posted on

Check If It Is a Straight Line : LeetCode

Problem Link: https://leetcode.com/problems/check-if-it-is-a-straight-line/

class Solution {

public boolean checkStraightLine(int[][] a) {

    double m = ((((a[1][1]-a[0][1]) * 100.0) / (a[1][0]-a[0][0]))*100.0);
    for(int i=2;i<a.length;i++){
        if((a[i][0]-a[i-1][0])==0){
           if(m!=Math.abs((((a[i][1]-a[i-1][1]) * 100.0) / (a[i][0]-a[i-1][0]))*100.0))
           return false; 
        }else{
            if(m!=((((a[i][1]-a[i-1][1]) * 100.0) / (a[i][0]-a[i-1][0]))*100.0))
           return false;
        }

    }

           return true;

}

}

Top comments (0)