Skip to content

Commit bd68a02

Browse files
authored
feat: add weekly contest 412 (doocs#3448)
1 parent f7895bb commit bd68a02

File tree

13 files changed

+1095
-1
lines changed

13 files changed

+1095
-1
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3264. K 次乘运算后的最终数组 I](https://leetcode.cn/problems/final-array-state-after-k-multiplication-operations-i)
10+
11+
[English Version](/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,一个整数&nbsp;<code>k</code>&nbsp;&nbsp;和一个整数&nbsp;<code>multiplier</code>&nbsp;。</p>
18+
19+
<p>你需要对 <code>nums</code>&nbsp;执行 <code>k</code>&nbsp;次操作,每次操作中:</p>
20+
21+
<ul>
22+
<li>找到 <code>nums</code>&nbsp;中的 <strong>最小</strong>&nbsp;值&nbsp;<code>x</code>&nbsp;,如果存在多个最小值,选择最 <strong>前面</strong>&nbsp;的一个。</li>
23+
<li>将 <code>x</code>&nbsp;替换为&nbsp;<code>x * multiplier</code>&nbsp;。</li>
24+
</ul>
25+
26+
<p>请你返回执行完 <code>k</code>&nbsp;次乘运算之后,最终的 <code>nums</code>&nbsp;数组。</p>
27+
28+
<p>&nbsp;</p>
29+
30+
<p><strong class="example">示例 1:</strong></p>
31+
32+
<div class="example-block">
33+
<p><span class="example-io"><b>输入:</b>nums = [2,1,3,5,6], k = 5, multiplier = 2</span></p>
34+
35+
<p><span class="example-io"><b>输出:</b>[8,4,6,5,6]</span></p>
36+
37+
<p><strong>解释:</strong></p>
38+
39+
<table>
40+
<tbody>
41+
<tr>
42+
<th>操作</th>
43+
<th>结果</th>
44+
</tr>
45+
<tr>
46+
<td>1 次操作后</td>
47+
<td>[2, 2, 3, 5, 6]</td>
48+
</tr>
49+
<tr>
50+
<td>2 次操作后</td>
51+
<td>[4, 2, 3, 5, 6]</td>
52+
</tr>
53+
<tr>
54+
<td>3 次操作后</td>
55+
<td>[4, 4, 3, 5, 6]</td>
56+
</tr>
57+
<tr>
58+
<td>4 次操作后</td>
59+
<td>[4, 4, 6, 5, 6]</td>
60+
</tr>
61+
<tr>
62+
<td>5 次操作后</td>
63+
<td>[8, 4, 6, 5, 6]</td>
64+
</tr>
65+
</tbody>
66+
</table>
67+
</div>
68+
69+
<p><strong class="example">示例 2:</strong></p>
70+
71+
<div class="example-block">
72+
<p><span class="example-io"><b>输入:</b></span>nums = [1,2], k = 3, multiplier = 4</p>
73+
74+
<p><span class="example-io"><b>输出:</b></span>[16,8]</p>
75+
76+
<p><strong>解释:</strong></p>
77+
78+
<table>
79+
<tbody>
80+
<tr>
81+
<th>操作</th>
82+
<th>结果</th>
83+
</tr>
84+
<tr>
85+
<td>1 次操作后</td>
86+
<td>[4, 2]</td>
87+
</tr>
88+
<tr>
89+
<td>2 次操作后</td>
90+
<td>[4, 8]</td>
91+
</tr>
92+
<tr>
93+
<td>3 次操作后</td>
94+
<td>[16, 8]</td>
95+
</tr>
96+
</tbody>
97+
</table>
98+
</div>
99+
100+
<p>&nbsp;</p>
101+
102+
<p><strong>提示:</strong></p>
103+
104+
<ul>
105+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
106+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
107+
<li><code>1 &lt;= k &lt;= 10</code></li>
108+
<li><code>1 &lt;= multiplier &lt;= 5</code></li>
109+
</ul>
110+
111+
<!-- description:end -->
112+
113+
## 解法
114+
115+
<!-- solution:start -->
116+
117+
### 方法一
118+
119+
<!-- tabs:start -->
120+
121+
#### Python3
122+
123+
```python
124+
125+
```
126+
127+
#### Java
128+
129+
```java
130+
131+
```
132+
133+
#### C++
134+
135+
```cpp
136+
137+
```
138+
139+
#### Go
140+
141+
```go
142+
143+
```
144+
145+
<!-- tabs:end -->
146+
147+
<!-- solution:end -->
148+
149+
<!-- problem:end -->
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3264. Final Array State After K Multiplication Operations I](https://leetcode.com/problems/final-array-state-after-k-multiplication-operations-i)
10+
11+
[中文文档](/solution/3200-3299/3264.Final%20Array%20State%20After%20K%20Multiplication%20Operations%20I/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer array <code>nums</code>, an integer <code>k</code>, and an integer <code>multiplier</code>.</p>
18+
19+
<p>You need to perform <code>k</code> operations on <code>nums</code>. In each operation:</p>
20+
21+
<ul>
22+
<li>Find the <strong>minimum</strong> value <code>x</code> in <code>nums</code>. If there are multiple occurrences of the minimum value, select the one that appears <strong>first</strong>.</li>
23+
<li>Replace the selected minimum value <code>x</code> with <code>x * multiplier</code>.</li>
24+
</ul>
25+
26+
<p>Return an integer array denoting the <em>final state</em> of <code>nums</code> after performing all <code>k</code> operations.</p>
27+
28+
<p>&nbsp;</p>
29+
<p><strong class="example">Example 1:</strong></p>
30+
31+
<div class="example-block">
32+
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,3,5,6], k = 5, multiplier = 2</span></p>
33+
34+
<p><strong>Output:</strong> <span class="example-io">[8,4,6,5,6]</span></p>
35+
36+
<p><strong>Explanation:</strong></p>
37+
38+
<table>
39+
<tbody>
40+
<tr>
41+
<th>Operation</th>
42+
<th>Result</th>
43+
</tr>
44+
<tr>
45+
<td>After operation 1</td>
46+
<td>[2, 2, 3, 5, 6]</td>
47+
</tr>
48+
<tr>
49+
<td>After operation 2</td>
50+
<td>[4, 2, 3, 5, 6]</td>
51+
</tr>
52+
<tr>
53+
<td>After operation 3</td>
54+
<td>[4, 4, 3, 5, 6]</td>
55+
</tr>
56+
<tr>
57+
<td>After operation 4</td>
58+
<td>[4, 4, 6, 5, 6]</td>
59+
</tr>
60+
<tr>
61+
<td>After operation 5</td>
62+
<td>[8, 4, 6, 5, 6]</td>
63+
</tr>
64+
</tbody>
65+
</table>
66+
</div>
67+
68+
<p><strong class="example">Example 2:</strong></p>
69+
70+
<div class="example-block">
71+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2], k = 3, multiplier = 4</span></p>
72+
73+
<p><strong>Output:</strong> <span class="example-io">[16,8]</span></p>
74+
75+
<p><strong>Explanation:</strong></p>
76+
77+
<table>
78+
<tbody>
79+
<tr>
80+
<th>Operation</th>
81+
<th>Result</th>
82+
</tr>
83+
<tr>
84+
<td>After operation 1</td>
85+
<td>[4, 2]</td>
86+
</tr>
87+
<tr>
88+
<td>After operation 2</td>
89+
<td>[4, 8]</td>
90+
</tr>
91+
<tr>
92+
<td>After operation 3</td>
93+
<td>[16, 8]</td>
94+
</tr>
95+
</tbody>
96+
</table>
97+
</div>
98+
99+
<p>&nbsp;</p>
100+
<p><strong>Constraints:</strong></p>
101+
102+
<ul>
103+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
104+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
105+
<li><code>1 &lt;= k &lt;= 10</code></li>
106+
<li><code>1 &lt;= multiplier &lt;= 5</code></li>
107+
</ul>
108+
109+
<!-- description:end -->
110+
111+
## Solutions
112+
113+
<!-- solution:start -->
114+
115+
### Solution 1
116+
117+
<!-- tabs:start -->
118+
119+
#### Python3
120+
121+
```python
122+
123+
```
124+
125+
#### Java
126+
127+
```java
128+
129+
```
130+
131+
#### C++
132+
133+
```cpp
134+
135+
```
136+
137+
#### Go
138+
139+
```go
140+
141+
```
142+
143+
<!-- tabs:end -->
144+
145+
<!-- solution:end -->
146+
147+
<!-- problem:end -->

0 commit comments

Comments
 (0)