We iterate from a parity case-analysis to a one-line solution. The "prove it's always possible, then return True" pattern crops up in more LeetCode problems than you'd think.
We iterate from a parity case-analysis to a one-line solution. The "prove it's always possible, then return True" pattern crops up in more LeetCode problems than you'd think.
You are given an array nums1 of n distinct integers.
You want to construct another array nums2 of length n such that the elements in nums2 are either all odd or all even.
For each index i, you must choose exactly one of the following (in any order):
nums2[i] = nums1[i]nums2[i] = nums1[i] - nums1[j], for an index j != iReturn true if it is possible to construct such an array, otherwise return false.