forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1408-StringMatchingInAnArray.cs
More file actions
34 lines (30 loc) · 972 Bytes
/
1408-StringMatchingInAnArray.cs
File metadata and controls
34 lines (30 loc) · 972 Bytes
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
//-----------------------------------------------------------------------------
// Runtime: 244ms
// Memory Usage: 31.6 MB
// Link: https://leetcode.com/submissions/detail/336944781/
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace LeetCode
{
public class _1408_StringMatchingInAnArray
{
public IList<string> StringMatching(string[] words)
{
Array.Sort(words, (a, b) => a.Length.CompareTo(b.Length));
var result = new List<string>();
for (int i = 0; i < words.Length - 1; i++)
{
for (int j = i + 1; j < words.Length; j++)
{
if (words[j].Contains(words[i]))
{
result.Add(words[i]);
break;
}
}
}
return result;
}
}
}