Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be5881a

Browse files
DI String Match
1 parent c180d57 commit be5881a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎LeetCode C#/Easy/159-DI String Match.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Link: https://leetcode.com/problems/di-string-match/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
public class Solution {
10+
public int[] DiStringMatch(string s)
11+
{
12+
var arr = new int[s.Length + 1];
13+
int left = 0;
14+
int right = s.Length;
15+
16+
for (int i = 0; i < s.Length; i++)
17+
{
18+
if (s[i] == 'I')
19+
arr[i] = left++;
20+
else
21+
arr[i] = right--;
22+
}
23+
24+
arr[s.Length] = left;
25+
26+
return arr;
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /