469. Convex Polygon

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

 

Note:

  1. There are at least 3 and at most 10,000 points.
  2. Coordinates are in the range -10,000 to 10,000.
  3. 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、题目描述

给定一个按顺序连接的多边形的顶点,判断该多边形是否为凸多边形。(凸多边形的定义)

注:

  1. 顶点个数至少为 3 个且不超过 10,000
  2. 坐标范围为 -10,00010,000
  3. 你可以假定给定的点形成的多边形均为简单多边形(简单多边形的定义)。换句话说,保证每个顶点处恰好是两条边的汇合点,并且这些边 互不相交 。

示例 1:

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

输出: True

解释:

img

示例 2:

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

输出: False

解释:

img

Difficulty:

Medium

Lock:

Prime

Company:

Google