LC: 422. Valid Word Square
422. Valid Word Square
Given an array of strings words, return true if it forms a valid word square.
A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).
Example 1:
Input: words = ["abcd","bnrt","crmy","dtye"]
Output: true
Explanation:
The 1st row and 1st column both read "abcd".
The 2nd row and 2nd column both read "bnrt".
The 3rd row and 3rd column both read "crmy".
The 4th row and 4th column both read "dtye".
Therefore, it is a valid word square.Example 2:
Input: words = ["abcd","bnrt","crm","dt"]
Output: true
Explanation:
The 1st row and 1st column both read "abcd".
The 2nd row and 2nd column both read "bnrt".
The 3rd row and 3rd column both read "crm".
The 4th row and 4th column both read "dt".
Therefore, it is a valid word square.Example 3:
Constraints:
1 <= words.length <= 5001 <= words[i].length <= 500words[i]consists of only lowercase English letters.
The Essence:
In einem gültigen Wortquadrat sollte eine Zeile mit Index i dieselbe Zeichenfolge mit einer Spalte mit demselben Index i haben.
Details:
Wir können List<String> words als Matrix annehmen und über die Zeilen und Spalten in einer verschachtelten for-Schleife iterieren, um Werte zu vergleichen. In dem entsprechenden PR kann der Problemlöser den Code finden.
Solutions: In dem entsprechenden PR kann der Problemlöser den Code finden:
Default Code:
Last updated