博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【leetcode】1037. Valid Boomerang
阅读量:6914 次
发布时间:2019-06-27

本文共 761 字,大约阅读时间需要 2 分钟。

题目如下:

boomerang is a set of 3 points that are all distinct and not in a straight line.

Given a list of three points in the plane, return whether these points are a boomerang.

 

Example 1:

Input: [[1,1],[2,3],[3,2]]Output: true

Example 2:

Input: [[1,1],[2,2],[3,3]]Output: false

 

Note:

  1. points.length == 3
  2. points[i].length == 2
  3. 0 <= points[i][j] <= 100

解题思路:本题就是判断三点是否在一条直线上,判断的方法也很简单,任意从这三个点中选取两组点对,如果这两组的点对的斜率相同,则在同一直线上。

代码如下:

class Solution(object):    def isBoomerang(self, points):        """        :type points: List[List[int]]        :rtype: bool        """        return (points[0][1]-points[1][1]) * (points[1][0]-points[2][0]) \               != (points[0][0]-points[1][0]) * (points[1][1]-points[2][1])

 

转载于:https://www.cnblogs.com/seyjs/p/10824004.html

你可能感兴趣的文章
Java笔试题解(13)
查看>>
我的友情链接
查看>>
Hbase的WAL在RegionServer基本调用过程
查看>>
sql语句中left join中的on与where的区别
查看>>
RHEL6.0源码编译安装小企鹅输入法fcitx-4.0.0
查看>>
JVM系列(一)
查看>>
mybatis中的choose标签的使用
查看>>
mysql数据库与web主机分离实验
查看>>
HTTP Status 400 - Required MultipartFile parameter 'logoFole' is not present
查看>>
关于java字符串常用一些api 效率比拼小结(java对大型的字符串api处理效率比拼)...
查看>>
PHP句法规则详解
查看>>
h2 数据文件解析
查看>>
DML、DDL、DCL区别
查看>>
freemarker集成shiro标签
查看>>
java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
查看>>
Spring Boot 2.x 启动全过程源码分析(上)入口类剖析
查看>>
Java应用性能管理工具 Pinpoint
查看>>
jQuery UI Accordion in ASP.NET MVC - feed with data from database
查看>>
Linux运维课之Mysql cluster随堂视频
查看>>
Android入门之创建一个AndroidStudio工程
查看>>