-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray999.java
More file actions
68 lines (66 loc) · 1.7 KB
/
Array999.java
File metadata and controls
68 lines (66 loc) · 1.7 KB
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
64
65
66
67
68
package array;
/**
* @ProjectName: leetcode
* @Package: array
* @ClassName: Array999
* @Author: markey
* @Description:
* @Date: 2019/10/17 22:23
* @Version: 1.0
*/
public class Array999 {
public int numRookCaptures(char[][] board) {
int iRook = 0;
int jRook = 0;
boolean findRook = false;
for (int i = 0; i < board.length && !findRook; i++) {
for (int j = 0; j < board[i].length && !findRook; j++) {
if (board[i][j] == 'R') {
findRook = true;
iRook = i;
jRook = j;
break;
}
}
}
System.out.println(iRook);
int count = 0;
for (int j = jRook + 1; j < board[iRook].length; j++) {
if (board[iRook][j] == '.') {
continue;
}
if (board[iRook][j] == 'p') {
count++;
}
break;
}
for (int j = jRook - 1; j >= 0; j--) {
if (board[iRook][j] == '.') {
continue;
}
if (board[iRook][j] == 'p') {
count++;
}
break;
}
for (int i = iRook - 1; i >= 0; i--) {
if (board[i][jRook] == '.') {
continue;
}
if (board[i][jRook] == 'p') {
count++;
}
break;
}
for (int i = iRook + 1; i < board.length; i++) {
if (board[i][jRook] == '.') {
continue;
}
if (board[i][jRook] == 'p') {
count++;
}
break;
}
return count;
}
}