반응형
내 코드
class Solution {
public int solution(int[][] dots) {
int w = 0;
int h = 0;
int x = dots[0][0];
int y = dots[0][1];
for(int i = 1 ; i < dots.length ; i++) {
if(x != dots[i][0]) w = Math.abs(x - dots[i][0]);
if(y != dots[i][1]) h = Math.abs(y - dots[i][1]);
}
return w * h;
}
}
다른 코드
class Solution {
public int solution(int[][] dots) {
int tmp = dots[0][0];
int w = 0;
int h = 0;
for(int i = 1 ; i < dots.length ; i++) {
if(dots[i][0] == tmp) {
h = Math.abs(dots[i][1] - dots[0][1]);
} else {
w = Math.abs(dots[i][0] - dots[0][0]);
}
}
return w * h;
}
}
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
반응형