[Programmers]_C++_Algorithm_바탕화면정리

신치우·2025년 2월 28일

C++_algorithm

목록 보기
13/17
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<string> wallpaper) {
    vector<int> answer = {-1, -1, -1, -1};
    
    for(int i=0; i<wallpaper.size(); i++){
        for(int j=0; j<wallpaper[0].size(); j++){
            if (wallpaper[i][j] == '#'){
                if(answer[0] == -1){
                    answer[0] = i;
                    answer[1] = j;
                    answer[2] = i+1;
                    answer[3] = j+1;
                } else {
                    answer[0] = min(answer[0], i);
                    answer[1] = min(answer[1], j);
                    answer[2] = max(answer[2], i+1);
                    answer[3] = max(answer[3], j+1);
                }
            }
        }
    }
    
    return answer;
}
profile
https://shin8037.tistory.com/

0개의 댓글