-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat: add new lc problems #4718
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
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
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
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
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
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
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
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
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
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
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
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
116 changes: 116 additions & 0 deletions
solution/3600-3699/3678.Smallest Absent Positive Greater Than Average/README.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,116 @@ | ||
--- | ||
comments: true | ||
difficulty: 简单 | ||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3678.Smallest%20Absent%20Positive%20Greater%20Than%20Average/README.md | ||
--- | ||
|
||
<!-- problem:start --> | ||
|
||
# [3678. 大于平均值的最小未出现正整数](https://leetcode.cn/problems/smallest-absent-positive-greater-than-average) | ||
|
||
[English Version](/solution/3600-3699/3678.Smallest%20Absent%20Positive%20Greater%20Than%20Average/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- description:start --> | ||
|
||
<p>给你一个整数数组 <code>nums</code>。</p> | ||
|
||
<p>返回 <code>nums</code> 中 <strong>严格大于</strong> <code>nums</code> 中所有元素 <strong>平均值</strong> 的 <strong>最小未出现正整数</strong>。</p> | ||
数组的 <strong>平均值</strong> 定义为数组中所有元素的总和除以元素的数量。 | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>输入:</strong> <span class="example-io">nums = [3,5]</span></p> | ||
|
||
<p><strong>输出:</strong> <span class="example-io">6</span></p> | ||
|
||
<p><strong>解释:</strong></p> | ||
|
||
<ul> | ||
<li><code>nums</code> 的平均值是 <code>(3 + 5) / 2 = 8 / 2 = 4</code> 。</li> | ||
<li>大于 4 的最小未出现正整数是 6。</li> | ||
</ul> | ||
</div> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>输入:</strong> <span class="example-io">nums = [-1,1,2]</span></p> | ||
|
||
<p><strong>输出:</strong> <span class="example-io">3</span></p> | ||
|
||
<p><strong>解释:</strong></p> | ||
|
||
<ul> | ||
<li><code>nums</code> 的平均值是 <code>(-1 + 1 + 2) / 3 = 2 / 3 = 0.667</code> 。</li> | ||
<li>大于 0.667 的最小未出现正整数是 3 。</li> | ||
</ul> | ||
</div> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>输入:</strong> <span class="example-io">nums = [4,-1]</span></p> | ||
|
||
<p><strong>输出:</strong> <span class="example-io">2</span></p> | ||
|
||
<p><strong>解释:</strong></p> | ||
|
||
<ul> | ||
<li><code>nums</code> 的平均值是 <code>(4 + (-1)) / 2 = 3 / 2 = 1.50</code>。</li> | ||
<li>大于 1.50 的最小未出现正整数是 2。</li> | ||
</ul> | ||
</div> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 100</code></li> | ||
<li><code>-100 <= nums[i] <= 100</code></li> | ||
</ul> | ||
|
||
<!-- description:end --> | ||
|
||
## 解法 | ||
|
||
<!-- solution:start --> | ||
|
||
### 方法一 | ||
|
||
<!-- tabs:start --> | ||
|
||
#### Python3 | ||
|
||
```python | ||
|
||
``` | ||
|
||
#### Java | ||
|
||
```java | ||
|
||
``` | ||
|
||
#### C++ | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
#### Go | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- solution:end --> | ||
|
||
<!-- problem:end --> |
113 changes: 113 additions & 0 deletions
solution/3600-3699/3678.Smallest Absent Positive Greater Than Average/README_EN.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,113 @@ | ||
--- | ||
comments: true | ||
difficulty: Easy | ||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3678.Smallest%20Absent%20Positive%20Greater%20Than%20Average/README_EN.md | ||
--- | ||
|
||
<!-- problem:start --> | ||
|
||
# [3678. Smallest Absent Positive Greater Than Average](https://leetcode.com/problems/smallest-absent-positive-greater-than-average) | ||
|
||
[中文文档](/solution/3600-3699/3678.Smallest%20Absent%20Positive%20Greater%20Than%20Average/README.md) | ||
|
||
## Description | ||
|
||
<!-- description:start --> | ||
|
||
<p>You are given an integer array <code>nums</code>.</p> | ||
|
||
<p>Return the <strong>smallest absent positive</strong> integer in <code>nums</code> such that it is <strong>strictly greater</strong> than the <strong>average</strong> of all elements in <code>nums</code>.</p> | ||
The <strong>average</strong> of an array is defined as the sum of all its elements divided by the number of elements. | ||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>Input:</strong> <span class="example-io">nums = [3,5]</span></p> | ||
|
||
<p><strong>Output:</strong> <span class="example-io">6</span></p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<ul> | ||
<li>The average of <code>nums</code> is <code>(3 + 5) / 2 = 8 / 2 = 4</code>.</li> | ||
<li>The smallest absent positive integer greater than 4 is 6.</li> | ||
</ul> | ||
</div> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>Input:</strong> <span class="example-io">nums = [-1,1,2]</span></p> | ||
|
||
<p><strong>Output:</strong> <span class="example-io">3</span></p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<ul> | ||
<li>The average of <code>nums</code> is <code>(-1 + 1 + 2) / 3 = 2 / 3 = 0.667</code>.</li> | ||
<li>The smallest absent positive integer greater than 0.667 is 3.</li> | ||
</ul> | ||
</div> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<div class="example-block"> | ||
<p><strong>Input:</strong> <span class="example-io">nums = [4,-1]</span></p> | ||
|
||
<p><strong>Output:</strong> <span class="example-io">2</span></p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<ul> | ||
<li>The average of <code>nums</code> is <code>(4 + (-1)) / 2 = 3 / 2 = 1.50</code>.</li> | ||
<li>The smallest absent positive integer greater than 1.50 is 2.</li> | ||
</ul> | ||
</div> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 100</code></li> | ||
<li><code>-100 <= nums[i] <= 100</code></li> | ||
</ul> | ||
|
||
<!-- description:end --> | ||
|
||
## Solutions | ||
|
||
<!-- solution:start --> | ||
|
||
### Solution 1 | ||
|
||
<!-- tabs:start --> | ||
|
||
#### Python3 | ||
|
||
```python | ||
|
||
``` | ||
|
||
#### Java | ||
|
||
```java | ||
|
||
``` | ||
|
||
#### C++ | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
#### Go | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- solution:end --> | ||
|
||
<!-- problem:end --> |
Oops, something went wrong.
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.