# ​LeetCode刷题实战469：凸多边形

https://leetcode-cn.com/problems/convex-polygon/

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.

## 示例

``[[0,0],[0,1],[1,1],[1,0]]输出：True``

``[[0,0],[0,10],[10,10],[10,0],[5,5]]输出：False`` ## 解题

AB=(x2-x1,y2-y1), AC=(x3-x1,y3-y1)

`class Solution:    def isConvex(self, points: List[List[int]]) -> bool:        def cal_cross_product(A, B, C):            AB = [B - A, B - A]            AC = [C - A, C - A]            return AB * AC - AB * AC        flag = 0        n = len(points)        for i in range(n):            # cur > 0 表示points是按逆时针输出的;cur < 0,顺时针            cur = cal_cross_product(points[i], points[(i + 1) % n], points[(i + 2) % n])            if cur != 0:                # 说明异号, 说明有个角大于180度                if cur * flag < 0:                    return False                else:                    flag = cur        return True`

LeetCode刷题实战463：岛屿的周长

LeetCode刷题实战467：环绕字符串中唯一的子字符串 