-
Notifications
You must be signed in to change notification settings - Fork 0
/
1652_lyingSpace.js
63 lines (52 loc) · 1.12 KB
/
1652_lyingSpace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 누울 자리를 찾아라, 1652
let fs = require("fs");
const [n, ...map] = fs.readFileSync("input.txt").toString().trim().split("\n");
console.log(rowFinder(map), colFinder(map));
function rowFinder(map) {
let result = 0;
for (let i = 0; i < n; i++) {
let combo = 0;
let prev = "";
for (let j = 0; j < n; j++) {
const current = map[i][j];
if (prev === "." && current === ".") {
combo++;
if (j === n - 1) {
result++;
combo = 0;
}
} else {
if (combo > 0) {
result++;
combo = 0;
}
}
prev = map[i][j];
}
}
return result;
}
function colFinder(map) {
let result = 0;
for (let i = 0; i < n; i++) {
let combo = 0;
let prev = "";
for (let j = 0; j < n; j++) {
const current = map[j][i];
if (prev === "." && current === ".") {
combo++;
if (j === n - 1) {
result++;
combo = 0;
}
} else {
if (combo > 0) {
result++;
combo = 0;
}
}
prev = map[j][i];
}
}
return result;
}