We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent aab04e1 commit 1d9f49cCopy full SHA for 1d9f49c
1 file changed
βing-eoking/무μΈλ μ¬ν.ccβ
@@ -0,0 +1,31 @@
1
+#include <string>
2
+#include <vector>
3
+#include <algorithm>
4
+
5
+using namespace std;
6
7
+int dx[4] = {-1, 0, 0, 1};
8
+int dy[4] = {0, -1, 1, 0};
9
10
+int dfs(int x, int y, vector<string> &m){
11
+ if(x < 0 || x >= m.size()) return 0;
12
+ if(y < 0 || y >= m[x].size()) return 0;
13
+ if(m[x][y] == 'X') return 0;
14
+ int sum = m[x][y] - '0';
15
+ m[x][y] = 'X';
16
+ for(int i = 0; i < 4; i++){
17
+ sum += dfs(x + dx[i], y + dy[i], m);
18
+ }
19
+ return sum;
20
+}
21
22
+vector<int> solution(vector<string> maps) {
23
+ vector<int> answer;
24
+ for(int i = 0; i < maps.size(); i++)
25
+ for(int j = 0; j < maps[i].size(); j++)
26
+ if(maps[i][j] != 'X')
27
+ answer.push_back(dfs(i, j, maps));
28
+ if(answer.empty()) return {-1};
29
+ sort(answer.begin(), answer.end());
30
+ return answer;
31
0 commit comments