Skip to content

Commit

Permalink
leetcode distribute elements into two arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas committed Mar 6, 2024
1 parent 230f398 commit 6a134fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions leetcode/algorithms/easy/distribute_elements_into_two_arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import List


class Solution:
def resultArray(self, nums: List[int]) -> List[int]:
r1, r2 = [], []
for i, e in enumerate(nums):
if i == 0:
r1.append(e)
elif i == 1:
r2.append(e)
else:
if r1[-1] > r2[-1]:
r1.append(e)
else:
r2.append(e)
return r1 + r2

0 comments on commit 6a134fd

Please sign in to comment.