File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 410
410
419|[ Battleships in a Board] ( ./solutions/0419-battleships-in-a-board.js ) |Medium|
411
411
420|[ Strong Password Checker] ( ./solutions/0420-strong-password-checker.js ) |Hard|
412
412
421|[ Maximum XOR of Two Numbers in an Array] ( ./solutions/0421-maximum-xor-of-two-numbers-in-an-array.js ) |Medium|
413
+ 422|[ Valid Word Square] ( ./solutions/0422-valid-word-square.js ) |Easy|
413
414
423|[ Reconstruct Original Digits from English] ( ./solutions/0423-reconstruct-original-digits-from-english.js ) |Medium|
414
415
424|[ Longest Repeating Character Replacement] ( ./solutions/0424-longest-repeating-character-replacement.js ) |Medium|
415
416
427|[ Construct Quad Tree] ( ./solutions/0427-construct-quad-tree.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 422. Valid Word Square
3
+ * https://leetcode.com/problems/valid-word-square/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an array of strings words, return true if it forms a valid word square.
7
+ *
8
+ * A sequence of strings forms a valid word square if the kth row and column read the same
9
+ * string, where 0 <= k < max(numRows, numColumns).
10
+ */
11
+
12
+ /**
13
+ * @param {string[] } words
14
+ * @return {boolean }
15
+ */
16
+ var validWordSquare = function ( words ) {
17
+ const rowCount = words . length ;
18
+
19
+ for ( let rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++ ) {
20
+ const row = words [ rowIndex ] ;
21
+ for ( let colIndex = 0 ; colIndex < row . length ; colIndex ++ ) {
22
+ if ( colIndex >= rowCount || rowIndex >= words [ colIndex ] . length
23
+ || row [ colIndex ] !== words [ colIndex ] [ rowIndex ] ) {
24
+ return false ;
25
+ }
26
+ }
27
+ }
28
+
29
+ return true ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments