Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd3ef8e

Browse files
feat: update solutions to lc problems: No.1929,1933 (doocs#3599)
* No.1929.Concatenation of Array * No.1933.Check if String Is Decomposable Into Value-Equal Substrings
1 parent 5ee2352 commit bd3ef8e

File tree

6 files changed

+21
-90
lines changed

6 files changed

+21
-90
lines changed

‎solution/1900-1999/1929.Concatenation of Array/README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ tags:
6767

6868
<!-- solution:start -->
6969

70-
### 方法一
70+
### 方法一:模拟
71+
72+
我们直接根据题目描述模拟,将 $\textit{nums}$ 中的元素依次添加到答案数组中,然后再将 $\textit{nums}$ 中的元素再次添加到答案数组中。
73+
74+
时间复杂度 $O(n),ドル空间复杂度 $O(n)$。其中 $n$ 为数组 $\textit{nums}$ 的长度。
7175

7276
<!-- tabs:start -->
7377

@@ -142,9 +146,7 @@ impl Solution {
142146
* @return {number[]}
143147
*/
144148
var getConcatenation = function (nums) {
145-
let ans = nums.slice();
146-
ans.splice(nums.length, 0, ...nums);
147-
return ans;
149+
return [...nums, ...nums];
148150
};
149151
```
150152

‎solution/1900-1999/1929.Concatenation of Array/README_EN.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ tags:
6060

6161
<!-- solution:start -->
6262

63-
### Solution 1
63+
### Solution 1: Simulation
64+
65+
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.
66+
67+
The time complexity is $O(n),ドル and the space complexity is $O(n)$. Here, $n$ is the length of the array $\textit{nums}$.
6468

6569
<!-- tabs:start -->
6670

@@ -135,9 +139,7 @@ impl Solution {
135139
* @return {number[]}
136140
*/
137141
var getConcatenation = function (nums) {
138-
let ans = nums.slice();
139-
ans.splice(nums.length, 0, ...nums);
140-
return ans;
142+
return [...nums, ...nums];
141143
};
142144
```
143145

‎solution/1900-1999/1929.Concatenation of Array/Solution.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
* @return {number[]}
44
*/
55
var getConcatenation = function (nums) {
6-
let ans = nums.slice();
7-
ans.splice(nums.length, 0, ...nums);
8-
return ans;
6+
return [...nums, ...nums];
97
};

‎solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README.md‎

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,14 @@ tags:
8282
```python
8383
class Solution:
8484
def isDecomposable(self, s: str) -> bool:
85-
i, n = 0, len(s)
8685
cnt2 = 0
87-
while i < n:
88-
j = i
89-
while j < n and s[j] == s[i]:
90-
j += 1
91-
if (j - i) % 3 == 1:
86+
for _, g in groupby(s):
87+
m = len(list(g))
88+
if m % 3 == 1:
9289
return False
93-
cnt2 += (j - i) % 3 == 2
90+
cnt2 += m % 3 == 2
9491
if cnt2 > 1:
9592
return False
96-
i = j
9793
return cnt2 == 1
9894
```
9995

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

202198
<!-- solution:end -->
203199

204-
<!-- solution:start -->
205-
206-
### 方法二
207-
208-
<!-- tabs:start -->
209-
210-
#### Python3
211-
212-
```python
213-
class Solution:
214-
def isDecomposable(self, s: str) -> bool:
215-
cnt2 = 0
216-
for _, g in groupby(s):
217-
m = len(list(g))
218-
if m % 3 == 1:
219-
return False
220-
cnt2 += m % 3 == 2
221-
if cnt2 > 1:
222-
return False
223-
return cnt2 == 1
224-
```
225-
226-
<!-- tabs:end -->
227-
228-
<!-- solution:end -->
229-
230200
<!-- problem:end -->

‎solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/README_EN.md‎

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,14 @@ The time complexity is $O(n),ドル where $n$ is the length of the string $s$. The sp
8383
```python
8484
class Solution:
8585
def isDecomposable(self, s: str) -> bool:
86-
i, n = 0, len(s)
8786
cnt2 = 0
88-
while i < n:
89-
j = i
90-
while j < n and s[j] == s[i]:
91-
j += 1
92-
if (j - i) % 3 == 1:
87+
for _, g in groupby(s):
88+
m = len(list(g))
89+
if m % 3 == 1:
9390
return False
94-
cnt2 += (j - i) % 3 == 2
91+
cnt2 += m % 3 == 2
9592
if cnt2 > 1:
9693
return False
97-
i = j
9894
return cnt2 == 1
9995
```
10096

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

203199
<!-- solution:end -->
204200

205-
<!-- solution:start -->
206-
207-
### Solution 2
208-
209-
<!-- tabs:start -->
210-
211-
#### Python3
212-
213-
```python
214-
class Solution:
215-
def isDecomposable(self, s: str) -> bool:
216-
cnt2 = 0
217-
for _, g in groupby(s):
218-
m = len(list(g))
219-
if m % 3 == 1:
220-
return False
221-
cnt2 += m % 3 == 2
222-
if cnt2 > 1:
223-
return False
224-
return cnt2 == 1
225-
```
226-
227-
<!-- tabs:end -->
228-
229-
<!-- solution:end -->
230-
231201
<!-- problem:end -->

‎solution/1900-1999/1933.Check if String Is Decomposable Into Value-Equal Substrings/Solution2.py‎

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /