0
Leetcode Problem 469. Convex Polygon
469. Convex Polygon
AI Mock Interview
Leetcode Solutions
Checking Convexity with Cross Product
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize two boolean variables
gotNegative
and
gotPositive
to
false
.
Iterate over each point in the polygon as point A.
For each point A, identify the next two points B and C, wrapping around the polygon if necessary.
Compute the cross product of vectors AB and BC.
If the cross product is negative, set
gotNegative
to
true
; if positive, set
gotPositive
to
true
.
If both
gotNegative
and
gotPositive
are
true
, return
false
as the polygon is not convex.
If the loop completes without finding conflicting signs, return
true
as the polygon is convex.
Checking Convexity by Angle Method
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...