From 4b2df683a40d48e4451a8ad0feab4673e6e3dae4 Mon Sep 17 00:00:00 2001 From: MH Hung Date: Mon, 8 Sep 2025 14:27:53 +0800 Subject: [PATCH] [#1317] feat(GetNoZeroIntegers): add C# solution --- .../csharp/Program.cs | 52 +++++++++++++++++++ .../csharp/csharp.csproj | 10 ++++ 2 files changed, 62 insertions(+) create mode 100644 problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/Program.cs create mode 100644 problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/csharp.csproj diff --git a/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/Program.cs b/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/Program.cs new file mode 100644 index 0000000..e5087b9 --- /dev/null +++ b/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/Program.cs @@ -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]}"); + } +} diff --git a/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/csharp.csproj b/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/csharp.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/problems/1317-convert-integer-to-the-sum-of-two-no-zero-integers/csharp/csharp.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +