[Programmers]_C++_Algorithm_이웃한칸

신치우·2025년 2월 17일

C++_algorithm

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

using namespace std;

int solution(vector<vector<string>> board, int h, int w) {
    int answer = 0;
    vector<int> dir_h = {1, 0, 0, -1};
    vector<int> dir_w = {0, 1, -1, 0};
    
    for (int i = 0; i< 4 ; i++){
        
        int new_h = h + dir_h[i];
        int new_w = w + dir_w[i];
        if ((new_h>=0) && new_h<board.size() && new_w>=0 && new_w<board[0].size()){
            if(board[new_h][new_w] == board[h][w])
                answer++;
        }
        
    }
    return answer;
}
profile
https://shin8037.tistory.com/

0개의 댓글