first thought
- first check the obvious situation such as the total sum can’t be divided by 4, or smaller than the maximum number * 4
- same as the combination problem, from index 0 to end, recursively find the combination which added up is equal to sum / 4(square side length)
- build a map to check the num is used or not, because each num can be used exactly once.
solution
|
|
problem
AC. But the time complexity is not good enough(118ms).
reason
- check from the biggest num may reduce some time
modification
|
|
problem
there is no difference…
modification
The fast solution check one side in the helper function. Mine is check one side and all sides in the helper using the params to control the recursion. I think there’s no difference, but just try it.
|
|
result
AC(20ms). But still wondering what’s the difference, maybe the times of recursion loop. I’ll update this when I figure out the reason.