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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1137. N-th Tribonacci Number (0) | 2024.04.25 |
---|---|
leetcode 3065. Minimum Operations to Exceed Threshold Value I (0) | 2024.04.24 |
leetcode 3079. Find the Sum of Encrypted Integers (0) | 2024.04.24 |
leetcode 3083. Existence of a Substring in a String and Its Reverse (0) | 2024.04.24 |
leetcode 3099. Harshad Number (0) | 2024.04.23 |
댓글