diagonal difference in java code example
Example 1: diagonal difference in java
int leftd=0;
int rightd=0;
int n=arr.size();
for(int i=0;i<n;i++)
{
leftd+=arr.get(i).get(i);
rightd+=arr.get(i).get(n-i-1);
}
int absd=Math.abs(leftd-rightd);
return absd;
Example 2: diagonal difference in java
int leftd=0;
int rightd=0;
int n=arr.size();
for(int i=0;i<n;i++)
{
leftd+=arr.get(i).get(i);
rightd+=arr.get(i).get(n-i-1);
}
int absd=Math.abs(leftd-rightd);
return absd;