forked from itcharge/AlgoNote
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from itcharge:main #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
Solutions/1317. 将整数转换为两个无零整数的和.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# [1317. 将整数转换为两个无零整数的和](https://leetcode.cn/problems/convert-integer-to-the-sum-of-two-no-zero-integers/) | ||
|
||
- 标签:数学 | ||
- 难度:简单 | ||
|
||
## 题目大意 | ||
|
||
**描述**:给定一个整数 $n$。 | ||
|
||
**要求**:返回一个由两个整数组成的列表 $[A, B],ドル满足: | ||
|
||
- $A$ 和 $B$ 都是无零整数。 | ||
- $A + B = n$。 | ||
|
||
**说明**: | ||
|
||
- **无零整数**:十进制表示中不含任何 0ドル$ 的正整数。 | ||
- 题目数据保证至少一个有效的解决方案。 | ||
- 如果存在多个有效解决方案,可以返回其中任意一个。 | ||
- 2ドル \le n \le 10^4$。 | ||
|
||
**示例**: | ||
|
||
- 示例 1: | ||
|
||
```Python | ||
输入:n = 2 | ||
输出:[1,1] | ||
解释:A = 1, B = 1. A + B = n 并且 A 和 B 的十进制表示形式都不包含任何 0。 | ||
``` | ||
|
||
- 示例 2: | ||
|
||
```Python | ||
输入:n = 11 | ||
输出:[2,9] | ||
``` | ||
|
||
## 解题思路 | ||
|
||
### 思路 1:枚举 | ||
|
||
1. 由于给定的 $n$ 范围为 $[1, 10000],ドル比较小,我们可以直接在 $[1, n)$ 的范围内枚举 $A,ドル并通过 $n - A$ 得到 $B$。 | ||
2. 在判断 $A$ 和 $B$ 中是否都不包含 0ドル$。如果都不包含 0ドル,ドル则返回 $[A, B]$。 | ||
|
||
### 思路 1:代码 | ||
|
||
```Python | ||
class Solution: | ||
def getNoZeroIntegers(self, n: int) -> List[int]: | ||
for A in range(1, n): | ||
B = n - A | ||
if '0' not in str(A) and '0' not in str(B): | ||
return [A, B] | ||
``` | ||
|
||
### 思路 1:复杂度分析 | ||
|
||
- **时间复杂度**:$O(n \times \log n)$。 | ||
- **空间复杂度**:$O(1)$。 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.