Skip to content
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

feat: update solutions to lc problems: No.1929,1933 #3599

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions solution/1900-1999/1929.Concatenation of Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ tags:

<!-- solution:start -->

### 方法一
### 方法一:模拟

我们直接根据题目描述模拟,将 $\textit{nums}$ 中的元素依次添加到答案数组中,然后再将 $\textit{nums}$ 中的元素再次添加到答案数组中。

时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为数组 $\textit{nums}$ 的长度。

<!-- tabs:start -->

Expand Down Expand Up @@ -142,9 +146,7 @@ impl Solution {
* @return {number[]}
*/
var getConcatenation = function (nums) {
let ans = nums.slice();
ans.splice(nums.length, 0, ...nums);
return ans;
return [...nums, ...nums];
};
```

Expand Down
10 changes: 6 additions & 4 deletions solution/1900-1999/1929.Concatenation of Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ tags:

<!-- solution:start -->

### Solution 1
### Solution 1: Simulation

We directly simulate according to the problem description by adding the elements of $\textit{nums}$ to the answer array one by one, and then adding the elements of $\textit{nums}$ to the answer array again.

The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array $\textit{nums}$.

<!-- tabs:start -->

Expand Down Expand Up @@ -135,9 +139,7 @@ impl Solution {
* @return {number[]}
*/
var getConcatenation = function (nums) {
let ans = nums.slice();
ans.splice(nums.length, 0, ...nums);
return ans;
return [...nums, ...nums];
};
```

Expand Down
4 changes: 1 addition & 3 deletions solution/1900-1999/1929.Concatenation of Array/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
* @return {number[]}
*/
var getConcatenation = function (nums) {
let ans = nums.slice();
ans.splice(nums.length, 0, ...nums);
return ans;
return [...nums, ...nums];
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,14 @@ tags:
```python
class Solution:
def isDecomposable(self, s: str) -> bool:
i, n = 0, len(s)
cnt2 = 0
while i < n:
j = i
while j < n and s[j] == s[i]:
j += 1
if (j - i) % 3 == 1:
for _, g in groupby(s):
m = len(list(g))
if m % 3 == 1:
return False
cnt2 += (j - i) % 3 == 2
cnt2 += m % 3 == 2
if cnt2 > 1:
return False
i = j
return cnt2 == 1
```

Expand Down Expand Up @@ -201,30 +197,4 @@ function isDecomposable(s: string): boolean {

<!-- solution:end -->

<!-- solution:start -->

### 方法二

<!-- tabs:start -->

#### Python3

```python
class Solution:
def isDecomposable(self, s: str) -> bool:
cnt2 = 0
for _, g in groupby(s):
m = len(list(g))
if m % 3 == 1:
return False
cnt2 += m % 3 == 2
if cnt2 > 1:
return False
return cnt2 == 1
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ The time complexity is $O(n)$, where $n$ is the length of the string $s$. The sp
```python
class Solution:
def isDecomposable(self, s: str) -> bool:
i, n = 0, len(s)
cnt2 = 0
while i < n:
j = i
while j < n and s[j] == s[i]:
j += 1
if (j - i) % 3 == 1:
for _, g in groupby(s):
m = len(list(g))
if m % 3 == 1:
return False
cnt2 += (j - i) % 3 == 2
cnt2 += m % 3 == 2
if cnt2 > 1:
return False
i = j
return cnt2 == 1
```

Expand Down Expand Up @@ -202,30 +198,4 @@ function isDecomposable(s: string): boolean {

<!-- solution:end -->

<!-- solution:start -->

### Solution 2

<!-- tabs:start -->

#### Python3

```python
class Solution:
def isDecomposable(self, s: str) -> bool:
cnt2 = 0
for _, g in groupby(s):
m = len(list(g))
if m % 3 == 1:
return False
cnt2 += m % 3 == 2
if cnt2 > 1:
return False
return cnt2 == 1
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->

This file was deleted.

Loading