473. Matchsticks to Square

Description

You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. 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 true if you can make this square and false otherwise.

Constraints

  • 1 <= matchsticks.length <= 15

  • 0 <= matchsticks[i] <= 109

Approach

  • Binarysearch

  • GeeksforGeeks

  • ProgramCreek

  • YouTube

Examples

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.

Solutions

Follow up

Last updated

Was this helpful?