Class Solution
-
- All Implemented Interfaces:
public final class Solution3046 - Split the Array.
Easy
You are given an integer array
numsof even length. You have to split the array into two partsnums1andnums2such that:nums1.length == nums2.length == nums.length / 2.nums1should contain distinct elements.nums2should also contain distinct elements.
Return
trueif it is possible to split the array, andfalseotherwise_._Example 1:
Input: nums = 1,1,2,2,3,4
Output: true
Explanation: One of the possible ways to split nums is nums1 = 1,2,3 and nums2 = 1,2,4.
Example 2:
Input: nums = 1,1,1,1
Output: false
Explanation: The only possible way to split nums is nums1 = 1,1 and nums2 = 1,1. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.
Constraints:
1 <= nums.length <= 100nums.length % 2 == 01 <= nums[i] <= 100
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanisPossibleToSplit(IntArray nums)-
-
Method Detail
-
isPossibleToSplit
final Boolean isPossibleToSplit(IntArray nums)
-
-
-
-