Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Leetcode - Easy] Largest Triangle Area #13

Merged
merged 2 commits into from
Dec 7, 2024

Conversation

BangDori
Copy link
Contributor

문제

Type Info
Platform Leetcode
Level Easy
Link https://leetcode.com/problems/largest-triangle-area/description/

풀이

Note

points 중 무작위 3개를 뽑았을 때, 가능한 모든 경우의 수 = O(N^3)

  1. 무작위 3개의 점을 선택한다. - brute force
  2. 세 점의 넓이를 구하고, 이전 최대값(maxArea)과 비교한다.
    2-1. 이전 최대값보다 크다면 최대값을 현재 넓이로 갱신한다.
  3. 최대값을 반환한다.

무작위 세 점의 넓이를 구하는 공식은 다음과 같다.

image

임의의 점 A, B, C를 세 등분으로 나눈다. 그리고 세 등분에 대한 넓이를 구한다.

△AOB = (bx - cx) * (ay - by)
△BOC = (bx - cx) * (by - cy)
△AOC = (cx - ax) * (by - cy)

△ABC = △AOB + △BOC + △AOC
     = (bx - cx) * (ay - by) + (bx - cx) * (by - cy) + (cx - ax) * (by - cy)
     = bx*ay - bx*by - cx*ay + cx*by + bx*by - bx*cy - cx*by + cx*cy + cx*by - cx*cy - ax*by + ax*cy
     = bx*ay - cx*ay + cx*by - bx*cy - ax*by + ax*cy

어려웠던 점

  • 세 점을 기준으로 넓이를 구하는 방법을 생각해내기가 어려웠음

알게된 점

  • Easy한 건 문제의 난이도가 아니라 내 머리라는 사실을 알게 되었음
  • 수학은 중요하다는 사실도 알게 되었음

@github-actions github-actions bot requested a review from asuan99 November 29, 2024 12:18
@github-actions github-actions bot merged commit fa34d96 into main Dec 7, 2024
2 checks passed
@github-actions github-actions bot deleted the largest-triangle-area branch December 7, 2024 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant