refactor: refactor project structure
This commit is contained in:
63
legacy/2264 largestGoodInteger/C#/Program.cs
Executable file
63
legacy/2264 largestGoodInteger/C#/Program.cs
Executable file
@@ -0,0 +1,63 @@
|
||||
public class Solution {
|
||||
public string LargestGoodInteger(string num)
|
||||
{
|
||||
// var count = 0;
|
||||
// char lastNum = 'a';
|
||||
// var numList = new List<int>();
|
||||
// for (var i = 0; i < num.Length; i++)
|
||||
// {
|
||||
// if (num[i] == lastNum)
|
||||
// {
|
||||
// count++;
|
||||
// if (count == 3)
|
||||
// {
|
||||
// numList.Add(int.Parse(num[i].ToString()));
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// count = 1;
|
||||
// }
|
||||
|
||||
// lastNum = num[i];
|
||||
// }
|
||||
|
||||
// if (numList.Count == 0)
|
||||
// {
|
||||
// return "";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var a = numList.Max().ToString();
|
||||
// return $"{a}{a}{a}";
|
||||
// }
|
||||
|
||||
string max = "";
|
||||
|
||||
for (int i = 0; i < num.Length - 2; i++)
|
||||
{
|
||||
if (num[i] == num[i + 1] && num[i] == num[i + 2])
|
||||
{
|
||||
string current = $"{num[i]}{num[i]}{num[i]}";
|
||||
|
||||
if (max == "") max = current;
|
||||
else
|
||||
{
|
||||
if (int.Parse(current) > int.Parse(max))
|
||||
max = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
class program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
var solution = new Solution();
|
||||
|
||||
Console.WriteLine(solution.LargestGoodInteger("6777133339"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user