bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 469. Convex Polygon

469. Convex Polygon

Leetcode Solutions

Checking Convexity with Cross Product

  1. Initialize two boolean variables gotNegative and gotPositive to false.
  2. Iterate over each point in the polygon as point A.
  3. For each point A, identify the next two points B and C, wrapping around the polygon if necessary.
  4. Compute the cross product of vectors AB and BC.
  5. If the cross product is negative, set gotNegative to true; if positive, set gotPositive to true.
  6. If both gotNegative and gotPositive are true, return false as the polygon is not convex.
  7. If the loop completes without finding conflicting signs, return true as the polygon is convex.
UML Thumbnail

Checking Convexity by Angle Method

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...