469. Convex Polygon

469. Convex Polygon

难度: Medium

刷题内容

原题连接

内容描述

Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition).



Note:

There are at least 3 and at most 10,000 points.
Coordinates are in the range -10,000 to 10,000.
You may assume the polygon formed by given points is always a simple polygon (Simple polygon definition). In other words, we ensure that exactly two edges intersect at each vertex, and that edges otherwise don't intersect each other.


Example 1:

[[0,0],[0,1],[1,1],[1,0]]

Answer: True

Explanation:
Example 2:

[[0,0],[0,10],[10,10],[10,0],[5,5]]

Answer: False

Explanation:

思路 1
- 时间复杂度: O(N)- 空间复杂度: O(1)

凸多边形wikipedia

  • The polygon is entirely contained in a closed half-plane defined by each of its edges.

how-do-determine-if-a-polygon-is-complex-convex-nonconvex

top Created with Sketch.