- 이름이 없는 동물의 아이디
SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL
- 최소직사각형
class Solution {
public int solution(int[][] sizes) {
for(int i=0;i<sizes.length;i++) {
int w = sizes[i][0];
int h = sizes[i][1];
int w1 = 0;
int h1 = 0;
if(w > w1) {
w1 = w;
}
if(h > h1) {
h = h1;
}
return h * w;
}
}
}
class Solution {
public int solution(int[][] sizes) {
int maxWidth = 0;
int maxHeight = 0;
for(int [] size : sizes) {
int w = Math.max(size[0], size[1]);
int h = Math.min(size[0], size[1]);
maxWidth = Math.max(maxWidth, w);
maxHeight = Math.max(maxHeight, h);
}
return maxWidth * maxHeight;
}
}
class Solution {
public int solution(int[][] sizes) {
int length = 0, height = 0;
for (int[] card : sizes) {
length = Math.max(length, Math.max(card[0], card[1]));
height = Math.max(height, Math.min(card[0], card[1]));
}
int answer = length * height;
return answer;
}
}
- 공원 산책
class Solution {
public int[] solution(String[] park, String[] routes) {
int H = park.length;
int W = park[0].length();
int r = 0, c=0;
for(int i = 0; i<H; i++) {
for(int j = 0; j<W;j++) {
if(park[i].charAt(j) == 'S') {
r = i;
c = j;
break;
}
}
}
int[] dr = {-1, 1, 0, 0};
int[] dc = {0, 0, -1, 1};
for(String route : routes) {
String[] split = route.split(" ");
String dir = split[0];
int count = Integer.parseInt(split[1]);
int dirIdx = 0;
if(dir.equals("N")) dirIdx = 0;
else if (dir.equals("S")) dirIdx = 1;
else if (dir.equals("W")) dirIdx = 2;
else if (dir.equals("E")) dirIdx = 3;
int nr = r;
int nc = c;
boolean canMove = true;
for(int i=0;i<count;i++) {
nr += dr[dirIdx];
nc += dc[dirIdx];
if(nr <0 || nr >= H || nc <0 || nc >= W || park[nr].charAt(nc) == 'X') {
canMove = false;
break;
}
}
if(canMove) {
r = nr;
c = nc;
}
}
return new int[] {r, c};
}
}