특정 키보다 큰 사람의 수 구하기
public int solution(int[] array, int height) {
int answer= 0;
for (int others : array) {
if (others > height) {
answer++;
}
}
return answer;
}
많이 쉬웠던 문제
직사각형 네 꼭짓점의 좌표가 주어졌을 때 직사각형의 넓이 구하기
public int solution(int[][] dots) {
int answer = 0;
int width = 0;
int height = 0;
for (int i = 0; i < 3; i++) {
if ((dots[3][0] - dots[i][0]) != 0) {
width = Math.abs(dots[3][0] - dots[i][0]);
}
if ((dots[3][1] - dots[i][1]) != 0) {
height = Math.abs(dots[3][1] - dots[i][1]);
}
}
answer = width * height;
return answer;
}
문제 조건에 네 꼭짓점의 순서에 대한 조건이 없어 반복 조건문으로 두 점의 x좌표와 y좌표를 비교해 0이 아니라면 절댓값으로 가로의 길이와 세로의 길이를 곱해 넓이는 구하는 방식을 사용했다.
이진수 더하기
못 품...