python-algorithm
leetcode 3069. Distribute Elements Into Two Arrays I
무적김두칠
2024. 4. 24. 07:41
https://leetcode.com/problems/distribute-elements-into-two-arrays-i/description/
1
2
3
4
5
6
7
8
9
10
11
|
class Solution:
def resultArray(self, nums: List[int]) -> List[int]:
arr1 = [nums[0]]
arr2 = [nums[1]]
for i in range(2, len(nums)):
if arr1[-1] > arr2[-1]:
arr1.append(nums[i])
elif arr1[-1] < arr2[-1]:
arr2.append(nums[i])
return arr1 + arr2
|
cs |
반응형