We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 78dad25 commit 2446f4bCopy full SHA for 2446f4b
Easy/Valid Word Square.java
@@ -1,16 +1,13 @@
1
class Solution {
2
- public boolean validWordSquare(List<String> words) {
3
- return IntStream.range(0, words.size())
4
- .allMatch(i -> words.get(i).equals(verticalRepresentation(words, i)));
5
- }
6
-
7
- private String verticalRepresentation(List<String> words, int col){
8
- StringBuilder sb = new StringBuilder();
9
- for (String word : words) {
10
- if (col < word.length()) {
11
- sb.append(word.charAt(col));
12
+ public boolean validWordSquare(List<String> words) {
+ int n = words.size();
+ for (int i = 0; i < n; i++){
+ for (int j = 0; j < words.get(i).length(); j++){
+ if(j >= n || words.get(j).length() <= i || words.get(j).charAt(i) != words.get(i).charAt(j)) {
+ return false;
+ }
+ return true;
13
}
14
- return sb.toString();
15
16
0 commit comments