You are viewing a single comment's thread. Return to all comments →
Can someone explain where i am wrong, i fail 17 cases
public static double solve(List<List<Integer>> coordinates) { // Write your code here int maxX, minX, maxY, minY; maxX = maxY = Integer.MIN_VALUE; minX = minY = Integer.MAX_VALUE; for(List<Integer> co : coordinates){ maxX = Math.max(co.get(0), maxX); minX = Math.min(co.get(0), minX); maxY = Math.max(co.get(1), maxY); minY = Math.min(co.get(1), minY); // if(co.get(0) == 0){ // if(co.get(1) > maxY) maxY = co.get(1); // else if(co.get(1) < minY) minY = co.get(1); // } else { // if(co.get(0) > maxX) maxX = co.get(0); // else if(co.get(0) < minX) minX = co.get(0); // } } double longest = maxX - minX; if(longest < maxY - minY) longest = maxY - minY; double temp; temp = Math.sqrt(maxX*maxX + minY*minY); if(longest < temp) longest = temp; temp = Math.sqrt(maxX*maxX + maxY*maxY); if(longest < temp) longest = temp; temp = Math.sqrt(minX*minX + minY*minY); if(longest < temp) longest = temp; temp = Math.sqrt(minX*minX + maxY*maxY); if(longest < temp) longest = temp; return longest; // int maxAbsX, maxAbsY; // if(maxX >= 0 && minX >= 0){ // maxAbsX = maxX; // } else if(maxX <= 0){ // maxAbsX = -minX; // } else{ // if(maxX > -minX) maxAbsX = maxX; // else maxAbsX = - minX; // } // if(maxY >= 0 && minY >= 0){ // maxAbsY = maxY; // } else if(maxY <= 0){ // maxAbsY = -minY; // } else { // if(maxY > -minY) maxAbsY = maxY; // else maxAbsY = - minY; // } // double distXY = Math.sqrt(maxAbsX*maxAbsX + maxAbsY * maxAbsY); // return Math.max(Math.max(distX, distY), distXY); }
Seems like cookies are disabled on this browser, please enable them to open this website
Most Distant
You are viewing a single comment's thread. Return to all comments →
Can someone explain where i am wrong, i fail 17 cases