888. effective word words Plaza *

888. Effective word square word

Chinese English

Given a sequence of words, check whether it constitutes a valid word square.
Place a valid word should satisfy the following conditions: For satisfying 0≤k<max(numRows numColumns)the kfirst krow and first kcolumn corresponding to the character string should be the same.

Sample

Sample 1

输入: 
[
  "abcd",
  "bnrt",
  "crmy",
  "dtye"
]
输出: true
解释:
第一行和第一列都是“abcd”。
第二行和第二列都是“bnrt”。
第三行和第三列都是“crmy”。
第四行和第四列都是“dtye”。

因此,这是一个有效的单词广场.

Sample 2

输入:
[
  "abcd",
  "bnrt",
  "crm",
  "dt"
]
输出: true
解释:
第一行和第一列都是“abcd”。
第二行和第二列都是“bnrt”。
第三行和第三列都是“crm”。
第四行和第四列都是“dt”。

因此,这是一个有效的单词广场.

Sample 3

输入: 
[
  "ball",
  "area",
  "read",
  "lady"
]
输出: false
解释:
第三行是 "read" 但是第三列是 "lead".

因此,这不是一个有效的单词广场.

Precautions

Given the number of words is at least 1 and not more than 500.
Word length is at least 1 and not more than 500.
Each word contains only lowercase letters a-z.

 
 
Input test data (one per line argument) how to interpret the test data?
    '' '
     General idea:
     a single cycle words, the vertical stitching performed, if the current string length is not enough, the character is not spliced
     2 initializes res, and each cycle is completed which will append into res, the last time. can be determined whether the same
     '' '
     DEF validWordSquare (Self, words): 
        RES = [] 
        J = 0 
        ## outer loop 
        for I in Range (len (words)): 
            current_s = ' ' 
            Z = 0 
            for J in Range (len (words)): 
                # judged necessary, there is a current string length enough problems, such as the fourth row, dt, does not exist in the fourth column 
                IF len (words [J])> I: 
                    ## which is a [ 1] [ 0 ], [ 2 ] [ 0 ], [ 3 ] [ 0 ] Such added, and then the next cycle is the second variation, the first constant 
                    current_s + = words [J] [I] 
            res.append (current_s) 
        IF RES == words:
             return True
         return False

 

 

Guess you like

Origin www.cnblogs.com/yunxintryyoubest/p/12571470.html