You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0400-0499/0422.Valid Word Square/README_EN.md
+11-30
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,13 @@ Therefore, it is NOT a valid word square.
73
73
74
74
<!-- solution:start -->
75
75
76
-
### Solution 1
76
+
### Solution 1: Iterative Check
77
+
78
+
We observe that if $words[i][j] \neq words[j][i]$, we can directly return `false`.
79
+
80
+
Therefore, we only need to iterate through each row, and then check whether each row satisfies $words[i][j] = words[j][i]$. Note that if the index is out of bounds, we also directly return `false`.
81
+
82
+
The time complexity is $O(n^2)$, where $n$ is the length of `words`. The space complexity is $O(1)`.
77
83
78
84
<!-- tabs:start -->
79
85
@@ -83,12 +89,10 @@ Therefore, it is NOT a valid word square.
0 commit comments