-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21-FindAbsoluteDifference.cs
44 lines (39 loc) · 1.28 KB
/
21-FindAbsoluteDifference.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
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Text;
namespace HackerRank
{
public class FindAbsoluteDifference_Result
{
public static void AbsoulteDifference(string strArray)
{
char[] str = strArray.ToCharArray();
Array.Sort(str);
decimal firstLetter_TotalLength = 0;
decimal secondLetter_TotalLength = 0;
for(int i = 0; i < str.Length; i++)
{
if(str[i]!= str[i + 1])
{
firstLetter_TotalLength = i + 1;
secondLetter_TotalLength = str.Length - firstLetter_TotalLength;
break;
}
}
decimal absolute_Diff = Math.Abs(firstLetter_TotalLength - secondLetter_TotalLength);
Console.WriteLine($"Absoulte difference is : {absolute_Diff}");
}
}
public class FindAbsoluteDifference_Solution
{
public static void Input()
{
//string str = "AAABBAB";
//FindAbsoluteDifference_Result.AbsoulteDifference(str);
//output 1
string str = "AAAAABBAB";
FindAbsoluteDifference_Result.AbsoulteDifference(str);
//output 3
}
}
}