You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #131 on September 15, 2026 11:11.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/magic-squares-in-grid/
Problem Summary
2d 그리드가 주어질 때 안에서 magic square가 되는 부분 그리드의 개수를 구하는 문제.
Solution
그냥 돌려주면 된다.
1-9까지의 distinct가 나와야 되고 가로, 세로, 대각선의 합이 다 같은지 확인한다.
최적화?
magic square의 특성을 잘 분석해보면 간단하게 풀 수 있다.
일단 행, 열, 대각선을 더해서 다 같으려면 15가 나와야 한다.
그리고 적절히 식을 정리하면 가운데는 5가 나와야 한다. 이런식으로 수학적으로 풀면 특정 조합밖에 답이 안 되는데 lee형님 솔루션 또는 에디토리얼 참고.
Source Code
All reactions