Class Solution
- java.lang.Object
-
- g0401_0500.s0473_matchsticks_to_square.Solution
-
public class Solution extends Object
473 - Matchsticks to Square.Medium
You are given an integer array
matchstickswherematchsticks[i]is the length of theithmatchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.Return
trueif you can make this square andfalseotherwise.Example 1:

Input: matchsticks = [1,1,2,2,2]
Output: true
Explanation: You can form a square with length 2, one side of the square came two sticks with length 1.
Example 2:
Input: matchsticks = [3,3,3,3,4]
Output: false
Explanation: You cannot find a way to form a square with all the matchsticks.
Constraints:
1 <= matchsticks.length <= 151 <= matchsticks[i] <= 108
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanmakesquare(int[] matchsticks)
-