Skip to content
LC-3069 Easy LeetCode

3069. Distribute Elements Into Two Arrays I

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 73% Topics: Array, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

# array
class Solution(object):
    def resultArray(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        a, b = [nums[0]], [nums[1]]
        for i in xrange(2, len(nums)):
            if a[-1] > b[-1]:
                a.append(nums[i])
            else:
                b.append(nums[i])
        return a+b

Solution from kamyu104/LeetCode-Solutions · MIT