-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0422-ValidWordSquare.cs
35 lines (29 loc) · 959 Bytes
/
0422-ValidWordSquare.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//-----------------------------------------------------------------------------
// Runtime: 96ms
// Memory Usage: 24.8 MB
// Link: https://leetcode.com/submissions/detail/358370209/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0422_ValidWordSquare
{
public bool ValidWordSquare(IList<string> words)
{
if (words == null || words.Count == 0) return true;
var n = words.Count;
for (int i = 0; i < n; i++)
{
var str1 = words[i];
for (int j = 0; j < str1.Length; j++)
{
if (j >= n) return false;
var str2 = words[j];
if (str2.Length <= i || str1[j] != str2[i])
return false;
}
}
return true;
}
}
}