-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0484-FindPermutation.cs
34 lines (31 loc) · 968 Bytes
/
0484-FindPermutation.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
//-----------------------------------------------------------------------------
// Runtime: 236ms
// Memory Usage: 35.6 MB
// Link: https://leetcode.com/submissions/detail/381388417/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _0484_FindPermutation
{
public int[] FindPermutation(string s)
{
var result = new int[s.Length + 1];
result[0] = 1;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == 'I')
result[i + 1] = i + 2;
else
{
var j = i;
while (i < s.Length && s[i] == 'D')
i++;
for (int k = j, num = i + 1; k <= i; k++, num--)
result[k] = num;
i--;
}
}
return result;
}
}
}