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 b9a3169

Browse files
committed
[20230411] Solve easy problem
1 parent 35ce63e commit b9a3169

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 905. Sort Array By Parity
2+
# https://leetcode.com/problems/sort-array-by-parity/description/
3+
4+
from typing import List
5+
6+
7+
class Solution:
8+
def sortArrayByParity(self, nums: List[int]) -> List[int]:
9+
i, j = 0, len(nums) - 1
10+
while i < j:
11+
if nums[i] % 2 != 0:
12+
nums[i], nums[j] = nums[j], nums[i]
13+
j -= 1
14+
else:
15+
i += 1
16+
return nums

0 commit comments

Comments
(0)

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