Skip to content

Commit 4672bc3

Browse files
committed
feat: update solutions to lc problems: No.0189,0238
1 parent 141af5c commit 4672bc3

File tree

6 files changed

+12
-93
lines changed

6 files changed

+12
-93
lines changed

solution/0100-0199/0189.Rotate Array/README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tags:
3838
<pre>
3939
<strong>输入:</strong>nums = [-1,-100,3,99], k = 2
4040
<strong>输出:</strong>[3,99,-1,-100]
41-
<strong>解释:</strong>
41+
<strong>解释:</strong>
4242
向右轮转 1 步: [99,-1,-100,3]
4343
向右轮转 2 步: [3,99,-1,-100]</pre>
4444

@@ -248,23 +248,4 @@ public class Solution {
248248

249249
<!-- solution:end -->
250250

251-
<!-- solution:start -->
252-
253-
### 方法二
254-
255-
<!-- tabs:start -->
256-
257-
#### Python3
258-
259-
```python
260-
class Solution:
261-
def rotate(self, nums: List[int], k: int) -> None:
262-
k %= len(nums)
263-
nums[:] = nums[-k:] + nums[:-k]
264-
```
265-
266-
<!-- tabs:end -->
267-
268-
<!-- solution:end -->
269-
270251
<!-- problem:end -->

solution/0100-0199/0189.Rotate Array/README_EN.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ rotate 3 steps to the right: [5,6,7,1,2,3,4]
3737
<pre>
3838
<strong>Input:</strong> nums = [-1,-100,3,99], k = 2
3939
<strong>Output:</strong> [3,99,-1,-100]
40-
<strong>Explanation:</strong>
40+
<strong>Explanation:</strong>
4141
rotate 1 steps to the right: [99,-1,-100,3]
4242
rotate 2 steps to the right: [3,99,-1,-100]
4343
</pre>
@@ -246,23 +246,4 @@ public class Solution {
246246

247247
<!-- solution:end -->
248248

249-
<!-- solution:start -->
250-
251-
### Solution 2
252-
253-
<!-- tabs:start -->
254-
255-
#### Python3
256-
257-
```python
258-
class Solution:
259-
def rotate(self, nums: List[int], k: int) -> None:
260-
k %= len(nums)
261-
nums[:] = nums[-k:] + nums[:-k]
262-
```
263-
264-
<!-- tabs:end -->
265-
266-
<!-- solution:end -->
267-
268249
<!-- problem:end -->

solution/0100-0199/0189.Rotate Array/Solution2.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

solution/0200-0299/0238.Product of Array Except Self/README.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ tags:
6161

6262
### 方法一:两次遍历
6363

64-
我们定义两个变量 $left$ 和 $right$,分别表示当前元素左边所有元素的乘积和右边所有元素的乘积。初始时 $left=1$, $right=1$。定义一个长度为 $n$ 的答案数组 $ans$。
64+
我们定义两个变量 $\textit{left}$ 和 $\textit{right}$,分别表示当前元素左边所有元素的乘积和右边所有元素的乘积。初始时 $\textit{left}=1$, $\textit{right}=1$。定义一个长度为 $n$ 的答案数组 $\textit{ans}$。
6565

66-
我们先从左到右遍历数组,对于遍历到的第 $i$ 个元素,我们用 $left$ 更新 $ans[i]$,然后 $left$ 乘以 $nums[i]$。
66+
我们先从左到右遍历数组,对于遍历到的第 $i$ 个元素,我们用 $\textit{left}$ 更新 $\textit{ans}[i]$,然后 $\textit{left}$ 乘以 $\textit{nums}[i]$。
6767

68-
然后,我们从右到左遍历数组,对于遍历到的第 $i$ 个元素,我们更新 $ans[i]$ 为 $ans[i] \times right$,然后 $right$ 乘以 $nums[i]$。
68+
然后,我们从右到左遍历数组,对于遍历到的第 $i$ 个元素,我们更新 $\textit{ans}[i]$ 为 $\textit{ans}[i] \times \textit{right}$,然后 $\textit{right}$ 乘以 $\textit{nums}[i]$。
6969

70-
遍历结束后,数组 `ans` 即为所求的答案
70+
遍历结束后,返回答案数组 $\textit{ans}$
7171

72-
时间复杂度 $O(n)$,其中 $n$ 是数组 `nums` 的长度。忽略答案数组的空间消耗,空间复杂度 $O(1)$。
72+
时间复杂度 $O(n)$,其中 $n$ 是数组 $\textit{nums}$ 的长度。忽略答案数组的空间消耗,空间复杂度 $O(1)$。
7373

7474
<!-- tabs:start -->
7575

@@ -258,22 +258,4 @@ class Solution {
258258

259259
<!-- solution:end -->
260260

261-
<!-- solution:start -->
262-
263-
### 方法二
264-
265-
<!-- tabs:start -->
266-
267-
#### TypeScript
268-
269-
```ts
270-
function productExceptSelf(nums: number[]): number[] {
271-
return nums.map((_, i) => nums.reduce((pre, val, j) => pre * (i === j ? 1 : val), 1));
272-
}
273-
```
274-
275-
<!-- tabs:end -->
276-
277-
<!-- solution:end -->
278-
279261
<!-- problem:end -->

solution/0200-0299/0238.Product of Array Except Self/README_EN.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ tags:
5151

5252
### Solution 1: Two Passes
5353

54-
We define two variables $left$ and $right$, which represent the product of all elements to the left and right of the current element respectively. Initially, $left=1$, $right=1$. Define an answer array $ans$ of length $n$.
54+
We define two variables $\textit{left}$ and $\textit{right}$ to represent the product of all elements to the left and right of the current element, respectively. Initially, $\textit{left} = 1$ and $\textit{right} = 1$. We define an answer array $\textit{ans}$ of length $n$.
5555

56-
We first traverse the array from left to right, for the $i$th element we update $ans[i]$ with $left$, then $left$ multiplied by $nums[i]$.
56+
First, we traverse the array from left to right. For the $i$-th element, we update $\textit{ans}[i]$ with $\textit{left}$, then multiply $\textit{left}$ by $\textit{nums}[i]$.
5757

58-
Then, we traverse the array from right to left, for the $i$th element, we update $ans[i]$ to $ans[i] \times right$, then $right$ multiplied by $nums[i]$.
58+
Next, we traverse the array from right to left. For the $i$-th element, we update $\textit{ans}[i]$ to $\textit{ans}[i] \times \textit{right}$, then multiply $\textit{right}$ by $\textit{nums}[i]$.
5959

60-
After the traversal, the array `ans` is the answer.
60+
After the traversal, we return the answer array $\textit{ans}$.
6161

62-
The time complexity is $O(n)$, where $n$ is the length of the array `nums`. Ignore the space consumption of the answer array, the space complexity is $O(1)$.
62+
The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. Ignoring the space consumption of the answer array, the space complexity is $O(1)$.
6363

6464
<!-- tabs:start -->
6565

@@ -248,22 +248,4 @@ class Solution {
248248

249249
<!-- solution:end -->
250250

251-
<!-- solution:start -->
252-
253-
### Solution 2
254-
255-
<!-- tabs:start -->
256-
257-
#### TypeScript
258-
259-
```ts
260-
function productExceptSelf(nums: number[]): number[] {
261-
return nums.map((_, i) => nums.reduce((pre, val, j) => pre * (i === j ? 1 : val), 1));
262-
}
263-
```
264-
265-
<!-- tabs:end -->
266-
267-
<!-- solution:end -->
268-
269251
<!-- problem:end -->

solution/0200-0299/0238.Product of Array Except Self/Solution2.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)