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 983e342

Browse files
added daily challenge
1 parent 8862c3d commit 983e342

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def rearrangeArray(self, nums: List[int]) -> List[int]:
3+
a, b, c = [], [], []
4+
for num in nums:
5+
if num > 0:
6+
a.append(num)
7+
else:
8+
b.append(num)
9+
count, c1, c2 = 0, 0, 0
10+
for num in nums:
11+
if count % 2 == 0:
12+
n = a[c1]
13+
c.append(n)
14+
c1 += 1
15+
else:
16+
n = b[c2]
17+
c.append(n)
18+
c2 += 1
19+
count += 1
20+
21+
return c

0 commit comments

Comments
(0)

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