this is a c++ version based on your solution

class Solution_0 { public: bool makesquare(vector<int> &nums) { int sideLineSum = accumulate(nums.begin(), nums.end(), 0); if (nums.size() < 4 || sideLineSum % 4 != 0 || *max_element(nums.begin(), nums.end()) > sideLineSum / 4) { return false; } vector<int> sums(4, 0); sort(nums.begin(), nums.end(), [](int a, int b) { return a > b; }); return helper(nums, 0, sums, sideLineSum / 4); } bool helper(vector<int> &nums, int index, vector<int> &sums, int target) { if (index == nums.size()) { return true; } for (int i = 0; i < 4; i++) { if (sums[i] + nums[index] <= target) { sums[i] += nums[index]; if (helper(nums, index + 1, sums, target)) { return true; } sums[i] -= nums[index]; } } return false; } };Matchsticks to Square