forked from DengWangBao/Leetcode-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidWordSquare.java
More file actions
22 lines (19 loc) · 558 Bytes
/
ValidWordSquare.java
File metadata and controls
22 lines (19 loc) · 558 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.List;
/**
* 这题还挺容易错
*/
public class ValidWordSquare {
public boolean validWordSquare(List<String> words) {
for (int i = 0; i < words.size(); i++) {
for (int j = 0; j < words.get(i).length(); j++) {
if (j >= words.size() || i >= words.get(j).length()) {
return false;
}
if (words.get(i).charAt(j) != words.get(j).charAt(i)) {
return false;
}
}
}
return true;
}
}