[#1317] feat(GetNoZeroIntegers): add C# solution
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// LeetCode 1317: Convert Integer To The Sum Of Two No Zero Integers
|
||||
// 難度: Easy
|
||||
// 日期: 2025-09-08
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int[] GetNoZeroIntegers(int n)
|
||||
{
|
||||
for (var i = 1; i < n; i++)
|
||||
{
|
||||
if (CheckIntegersWithNoZero(i) && CheckIntegersWithNoZero(n - i))
|
||||
{
|
||||
return new int[]{i, n - i};
|
||||
}
|
||||
}
|
||||
return new int[]{};
|
||||
}
|
||||
|
||||
private bool CheckIntegersWithNoZero(int n)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
if (n % 10 == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
n /= 10;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class Program {
|
||||
public static void Main() {
|
||||
var Solution = new Solution();
|
||||
TestCase1(Solution);
|
||||
// TestCase2();
|
||||
}
|
||||
|
||||
static void TestCase1(Solution Solution) {
|
||||
// Input:
|
||||
var input = 1010;
|
||||
// Expected: [11, 999]
|
||||
int[] result = Solution.GetNoZeroIntegers(input);
|
||||
// Actual:
|
||||
Console.WriteLine($"Test 1: {result[0]}, {result[1]}");
|
||||
}
|
||||
}
|
@@ -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>
|
Reference in New Issue
Block a user