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 931d906

Browse files
Determine if String Halves Are Alike
1 parent db38014 commit 931d906

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Link: https://leetcode.com/problems/determine-if-string-halves-are-alike/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
10+
public class Solution {
11+
public bool HalvesAreAlike(string s)
12+
{
13+
string vowels = "aeiouAEIOU";
14+
string a = s.Substring(0, s.Length / 2);
15+
string b = s.Substring(s.Length / 2, s.Length / 2);
16+
int c1 = 0, c2 = 0;
17+
18+
for (int i = 0; i < a.Length; i++)
19+
{
20+
if (vowels.Contains(a[i]))
21+
c1++;
22+
}
23+
24+
for (int i = 0; i < b.Length; i++)
25+
{
26+
if (vowels.Contains(b[i]))
27+
c2++;
28+
}
29+
30+
return c1 == c2;
31+
}
32+
}

0 commit comments

Comments
(0)

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