Open Shawngbk opened 7 years ago
(i,j) (j,i)这两个坐标的字符必须相同,而且所在的行列长度相同 public class Solution { public boolean validWordSquare(List words) { int row = words.size(); if(row == 0) return true; int col = words.get(0).length(); if(row != col) return false; for(int i = 0; i < row; i++) { if(row < words.get(i).length()) return false; for(int j = 0; j < words.get(i).length(); j++) { if(row <= j || words.get(j).length() <= i || words.get(j).charAt(i) != words.get(i).charAt(j)) return false; } } return true; } }
google
(i,j) (j,i)这两个坐标的字符必须相同,而且所在的行列长度相同 public class Solution { public boolean validWordSquare(List words) {
int row = words.size();
if(row == 0)
return true;
int col = words.get(0).length();
if(row != col)
return false;
for(int i = 0; i < row; i++) {
if(row < words.get(i).length())
return false;
for(int j = 0; j < words.get(i).length(); j++) {
if(row <= j || words.get(j).length() <= i
|| words.get(j).charAt(i) != words.get(i).charAt(j))
return false;
}
}
return true;
}
}