-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0567-PermutationInString.cs
38 lines (31 loc) · 1.01 KB
/
0567-PermutationInString.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
36
37
38
//-----------------------------------------------------------------------------
// Runtime: 92ms
// Memory Usage: 23.7 MB
// Link: https://leetcode.com/submissions/detail/341590841/
//-----------------------------------------------------------------------------
using System.Linq;
namespace LeetCode
{
public class _0567_PermutationInString
{
public bool CheckInclusion(string s1, string s2)
{
var s1Length = s1.Length;
var s2Length = s2.Length;
if (s1Length > s2Length) return false;
var s1Count = new int[26];
foreach (var ch in s1)
s1Count[ch - 'a']++;
var s2Count = new int[26];
for (int i = 0; i < s2Length; i++)
{
s2Count[s2[i] - 'a']++;
if (i >= s1Length)
s2Count[s2[i - s1Length] - 'a']--;
if (s2Count.SequenceEqual(s1Count))
return true;
}
return false;
}
}
}