Files
coding-practice/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/Program.cs

53 lines
1.1 KiB
C#

// 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]}");
}
}