![[Lv. 1] 바탕화면 정리 [Lv. 1] 바탕화면 정리](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
이것도 그냥 어차피 2차원 배열로 풀고 가장 큰 x,y 좌표를 저장하는 변수를 선언 해놓고 마지막에 이 좌표값에 그냥 + 1 하면 되는거 아니야??하고 냅다 풀어봤는데 그냥 풀렸다.. 넘쳐나는 if문의 향연... 분명 더 좋은 방법이 있을텐데
class Solution {
public int[] solution(String[] wallpaper) {
int[] answer = new int[4];
int lastX = wallpaper[0].length();
int lastY = wallpaper.length;
int maxX = 0;
int maxY = 0;
for(int i = 0; i < wallpaper.length; i++){
for(int j = 0; j < wallpaper[0].length(); j++){
int currentX = j;
int currentY = i;
if(wallpaper[i].charAt(j) == '#'){
if(lastX > currentX){
lastX = currentX;
}
if(lastY > currentY){
lastY = currentY;
}
if(maxX < currentX){
maxX = currentX;
}
if(maxY < currentY){
maxY = currentY;
}
}
}
}
answer[0] = lastY;
answer[1] = lastX;
answer[2] = maxY + 1;
answer[3] = maxX + 1;
return answer;
}
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Lv. 1] 푸드 파이트 대회 (0) | 2023.09.07 |
---|---|
[Lv. 2] 점프와 순간 이동 (0) | 2023.08.20 |
[Lv. 1] 신규 아이디 추천 (0) | 2023.08.20 |
[Lv. 2] 카펫 (0) | 2023.08.08 |
[Lv. 1] 달리기 경주 (0) | 2023.08.08 |
댓글