Check If It Is a Straight Line : LeetCode

animeshy2jj

Animesh Kumar

Posted on October 4, 2020

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;

}

}

💖 💪 🙅 🚩
animeshy2jj
Animesh Kumar

Posted on October 4, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related