473. Matchsticks to Square Medium
1/**
2 * [473] Matchsticks to Square
3 *
4 * You are given an integer array matchsticks where matchsticks[i] is the length of the i^th 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.
5 * Return true if you can make this square and false otherwise.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/matchsticks1-grid.jpg" style="width: 253px; height: 253px;" />
9 * Input: matchsticks = [1,1,2,2,2]
10 * Output: true
11 * Explanation: You can form a square with length 2, one side of the square came two sticks with length 1.
12 *
13 * Example 2:
14 *
15 * Input: matchsticks = [3,3,3,3,4]
16 * Output: false
17 * Explanation: You cannot find a way to form a square with all the matchsticks.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= matchsticks.length <= 15
23 * 1 <= matchsticks[i] <= 10^8
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/matchsticks-to-square/
29// discuss: https://leetcode.com/problems/matchsticks-to-square/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn makesquare(matchsticks: Vec<i32>) -> bool {
35 false
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_473() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.