algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

distribute-elements-into-two-arrays-i.py (391B)


      1 class Solution:
      2     def resultArray(self, nums: List[int]) -> List[int]:
      3         arr1 = []
      4         arr2 = []
      5 
      6         arr1.append(nums[0])
      7         arr2.append(nums[1])
      8 
      9         for i in range(2, len(nums)):
     10             if arr1[-1] > arr2[-1]:
     11                 arr1.append(nums[i])
     12             else:
     13                 arr2.append(nums[i])
     14         
     15         arr1.extend(arr2)
     16 
     17         return arr1