← 返回 bloomberg 的题目列表Matchsticks to Square Transform
类型:online_judge
bloomberg
You have a box of matchsticks, and your task is to use these matchsticks to build a square. Each matchstick has a positive integer length and you need to find out if you can make a square using all of the matchsticks. You cannot break any matchstick, and you must use each matchstick exactly once. The total length of matchsticks should be divisible by 4. Return true if you can use all of the matchsticks to make a square, otherwise return false.
Input:
An array of positive integers representing the lengths of matchsticks, n (1 ≤ n ≤ 15), where the total length of matchsticks does not exceed 10^9.
Output:
A boolean value, true if you can make a square, false if you can't.
Examples:
Input: [1,1,2,2,2]
Output: true
Explanation: You can use these matchsticks to form a square with side length 2.
Input: [3,3,3,3,4]
Output: false
Explanation: You cannot make a square with these matchsticks.
Example
Input
[1,1,2,2,2]