Compare commits
3 Commits
cf3a952d1d
...
f4a7029b7e
Author | SHA1 | Date | |
---|---|---|---|
f4a7029b7e | |||
31d68d2f04 | |||
4b2df683a4 |
@@ -9,12 +9,13 @@
|
|||||||
| 09/02 | Find The Number of Ways to Place People I | Medium | C#, go | 0.7hr | Done | 二維點位判斷 |
|
| 09/02 | Find The Number of Ways to Place People I | Medium | C#, go | 0.7hr | Done | 二維點位判斷 |
|
||||||
| 09/03 | Find The Number of Ways to Place People II | Hard | C# | 0.2hr | Done | Same as [#3025] |
|
| 09/03 | Find The Number of Ways to Place People II | Hard | C# | 0.2hr | Done | Same as [#3025] |
|
||||||
| 09/04 | Find Closest Person | Easy | C#, go | 0.1hr | Done | 數學判斷 |
|
| 09/04 | Find Closest Person | Easy | C#, go | 0.1hr | Done | 數學判斷 |
|
||||||
|
| 09/05 | Minimum Operations to Make the Integer Zero | Medium | C# | 1.5hr | Done | |
|
||||||
|
|
||||||
|
|
||||||
### Week 2
|
### Week 2
|
||||||
| 日期 | 題目 | 難度 | 語言 | 耗時 | 狀態 | 心得 |
|
| 日期 | 題目 | 難度 | 語言 | 耗時 | 狀態 | 心得 |
|
||||||
|------|------|------|------|------|------|------|
|
|------|------|------|------|------|------|------|
|
||||||
| | | | | | | |
|
| 09/08 | Convert Integer To The Sum Of Two No Zero Integers | Easy | C# | 0.2hr | Done | |
|
||||||
|
|
||||||
### Week 3
|
### Week 3
|
||||||
| 日期 | 題目 | 難度 | 語言 | 耗時 | 狀態 | 心得 |
|
| 日期 | 題目 | 難度 | 語言 | 耗時 | 狀態 | 心得 |
|
||||||
@@ -29,13 +30,13 @@
|
|||||||
## 📈 本月統計
|
## 📈 本月統計
|
||||||
|
|
||||||
### 完成情況
|
### 完成情況
|
||||||
- **總練習天數**: 4 天
|
- **總練習天數**: 6 天
|
||||||
- **完成題數**: 4題
|
- **完成題數**: 6題
|
||||||
- **語言分布**: C# 4(題), Go 2(題)
|
- **語言分布**: C# 6(題), Go 2(題)
|
||||||
- **難度分布**: Easy 1(題), Medium 2(題), Hard 1(題)
|
- **難度分布**: Easy 2(題), Medium 3(題), Hard 1(題)
|
||||||
|
|
||||||
### 時間投入
|
### 時間投入
|
||||||
- **總時間**: 2小時
|
- **總時間**: 3.7小時
|
||||||
- **平均每題**: 分鐘
|
- **平均每題**: 分鐘
|
||||||
- **每日平均**: 分鐘
|
- **每日平均**: 分鐘
|
||||||
|
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
# [1317] Convert Integer To The Sum Of Two No Zero Integers
|
||||||
|
|
||||||
|
## 題目資訊
|
||||||
|
- **難度**: Easy
|
||||||
|
- **標籤**: Math
|
||||||
|
- **題目連結**: [LeetCode](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/)
|
||||||
|
- **練習日期**: 2025-09-08
|
||||||
|
|
||||||
|
## 題目描述
|
||||||
|
No-Zero integer is a positive integer that does not contain any `0` in its decimal representation.
|
||||||
|
|
||||||
|
Given an integer `n`, return a list of two integers `[a, b]` where:
|
||||||
|
|
||||||
|
- `a` and `b` are No-Zero integers.
|
||||||
|
- `a + b = n`
|
||||||
|
The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.
|
||||||
|
|
||||||
|
## 解題思路
|
||||||
|
|
||||||
|
### 初步分析
|
||||||
|
- 這題主要考察什麼概念?
|
||||||
|
迴圈遍歷 + 數字位數檢查
|
||||||
|
- 有什麼關鍵限制條件?
|
||||||
|
1. 兩個數都必須是正整數
|
||||||
|
2. 兩個數的十進制表示都不能包含數字 0
|
||||||
|
3. 兩個數相加必須等於 n
|
||||||
|
- 預期時間/空間複雜度?
|
||||||
|
|
||||||
|
### 解法概述
|
||||||
|
**解法**:
|
||||||
|
- 思路:
|
||||||
|
1. 從 i = 1 開始遍歷到 n-1
|
||||||
|
2. 對每個 i,檢查 i 和 (n-i) 是否都不包含數字 0
|
||||||
|
3. 找到第一個滿足條件的組合就返回
|
||||||
|
- 時間複雜度:O(n)
|
||||||
|
- 空間複雜度:O(1)
|
||||||
|
|
||||||
|
## 測試案例
|
||||||
|
|
||||||
|
### 範例輸入輸出
|
||||||
|
```
|
||||||
|
Input: n = 2
|
||||||
|
Output: [1,1]
|
||||||
|
Explanation: Let a = 1 and b = 1.
|
||||||
|
Both a and b are no-zero integers, and a + b = 2 = n.
|
||||||
|
```
|
||||||
|
|
||||||
|
### 邊界情況
|
||||||
|
2 <= n <= 10^4
|
||||||
|
|
||||||
|
## 學習筆記
|
||||||
|
|
||||||
|
### 今天學到什麼?
|
||||||
|
-
|
||||||
|
|
||||||
|
### 遇到的困難
|
||||||
|
-
|
||||||
|
|
||||||
|
### 改善方向
|
||||||
|
-
|
||||||
|
|
||||||
|
### 相關題目
|
||||||
|
|
||||||
|
---
|
||||||
|
**總結**: 這題的核心概念是...,適合練習...技巧。
|
@@ -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