Merge pull request '2508/2264' (#7) from 2508/2264 into main
Reviewed-on: #7
This commit is contained in:
24
202508/2264 largestGoodInteger/C#/C#.sln
Normal file
24
202508/2264 largestGoodInteger/C#/C#.sln
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.2.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "largestGoodInteger", "largestGoodInteger.csproj", "{DF73131C-3A52-FFDC-7C0C-19190AA3E331}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {E9F3A871-90C4-4B8E-81E2-B0AF873694BF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
63
202508/2264 largestGoodInteger/C#/Program.cs
Normal file
63
202508/2264 largestGoodInteger/C#/Program.cs
Normal 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"));
|
||||||
|
}
|
||||||
|
}
|
10
202508/2264 largestGoodInteger/C#/largestGoodInteger.csproj
Normal file
10
202508/2264 largestGoodInteger/C#/largestGoodInteger.csproj
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
23
202508/2264 largestGoodInteger/GO/main.go
Normal file
23
202508/2264 largestGoodInteger/GO/main.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func LargestGoodInteger(num string) string {
|
||||||
|
max := ""
|
||||||
|
|
||||||
|
for i := 0; i < len(num)-2; i++ {
|
||||||
|
if num[i] == num[i+1] && num[i] == num[i+2] {
|
||||||
|
current := string([]byte{num[i], num[i], num[i]})
|
||||||
|
|
||||||
|
if current > max {
|
||||||
|
max = current
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(LargestGoodInteger("7636669283"))
|
||||||
|
}
|
Reference in New Issue
Block a user