自己的提交:

class Solution:
def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
if not coordinates: return False
if len(coordinates) <= 2:
return True
k = float("inf") if coordinates[1][0] - coordinates[0][0] == 0 else (coordinates[1][1] - coordinates[0][1]) / (coordinates[1][0] - coordinates[0][0])
for i in range(2,len(coordinates)):
k1 = float("inf") if coordinates[i][0] - coordinates[i-1][0] == 0 else (coordinates[i][1] - coordinates[i-1][1]) / (coordinates[i][0] - coordinates[i-1][0])
if k1 != k:
return False
return True

另:

class Solution:
def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
n = len(coordinates)
if n <= 2:
return True
x1, y1 = coordinates[0][0] - coordinates[1][0], coordinates[0][1] - coordinates[1][1]
for i in range(2, n):
x2, y2 = coordinates[0][0] - coordinates[i][0], coordinates[0][1] - coordinates[i][1]
if x1 * y2 - x2 * y1 != 0:
return False
return True

leetcode-159周赛-5230-缀点成线的更多相关文章

  1. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  2. 【LeetCode】To Lower Case(转换成小写字母)

    这道题是LeetCode里的第709道题. 题目要求: 实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: ...

  3. LeetCode 709. To Lower Case (转换成小写字母)

    题目标签:String 题目让我们把大写字母转换成小写,只要遇到的是大写字母,把它 + 32 变成 小写就可以了. Java Solution: Runtime beats 100.00% 完成日期: ...

  4. [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string s , find the length of the longest substring t  that contains at most 2 distinct char ...

  5. LeetCode随缘刷题之转化成小写字母

    这道题应该是最简单的一道题了把,简直在侮辱我. package leetcode.day_12_12; /** * 709. 转换成小写字母 * 给你一个字符串 s ,将该字符串中的大写字母转换成相同 ...

  6. [LeetCode] Roman to Integer 罗马数字转化成整数

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  7. IT关键词,发现与更新,点成线,线成面,面成体

    时序图 1.什么是时序图 2.如何看懂时序图 3.时序图的作用 4.如何绘制时序图 分布式 一个业务分拆多个子业务,部署在不同的服务器上. 分布式是指将不同的业务分布在不同的地方. 而集群指的是将几台 ...

  8. ✡ leetcode 159. Longest Substring with At Most Two Distinct Characters 求两个字母组成的最大子串长度 --------- java

    Given a string, find the length of the longest substring T that contains at most 2 distinct characte ...

  9. [leetcode]131. Palindrome Partitioning字符串分割成回文子串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

随机推荐

  1. Codeforces 631E 斜率优化

    题意:给你一个数组,你可以选择数组中的一个数,把它插入数组的其它位置,问∑ i * a[i]的最大值为多少? 思路:设dp[i]表示把第i个数向左边插入可以获得的最大增量,我们假设向左边插入,设插入的 ...

  2. Web UI开发神器—Kendo UI for jQuery数据管理之过滤操作

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  3. java输入一个整数N,打印1~n位数

    举个栗子:输入 3 : 打印1,2,3......999 这里要注意一个坑,不可以直接算出最大的数,然后从1开始打印 .因为当n足够大时,n位数必定会超出int范围和long范围 所以我们需要用字符串 ...

  4. python判断文件的编码格式是否为UTF8 无BOM格式

    转自: https://www.cnblogs.com/ferraborghini/p/4951102.html https://www.cnblogs.com/Detector/p/8744992. ...

  5. Shiro学习(12)与Spring集成

    Shiro的组件都是JavaBean/POJO式的组件,所以非常容易使用spring进行组件管理,可以非常方便的从ini配置迁移到Spring进行管理,且支持JavaSE应用及Web应用的集成. 在示 ...

  6. elementUI表格行的点击事件,点击表格,拿到当前行的数据

    1.绑定事件 2.定义事件 3.点击表格某行的时候,拿到数据]

  7. [NOIP模拟14]题解

    当垃圾已经成为一种常态233333 A.旋转子段 考场上的$n^2$手残少了20分,555  (主要是因为实在打不出来$n^3$的做法所以写不了对拍?ccc为什么考场上没有想起有reverse()这么 ...

  8. (转)微信,QQ这类IM app怎么做——谈谈Websocket

    转:http://www.cocoachina.com/ios/20160527/16482.html 前言 关于我和WebSocket的缘:我从大二在计算机网络课上听老师讲过之后,第一次使用就到了毕 ...

  9. mongodb update操作

    //修改字段名称,把synonymsList表的name_status修改为status db.getCollection('synonymsList').update({}, {$rename : ...

  10. nginx填坑补充(nginx根据上下文跳转ip或者域名)

    今天有一个需求,要根据上下文调到不同的ip或域名地址,使用上下文做域名跳转的时候,proxy_pass域名后面一定要带‘/’否则会把nginx的上下文自动带入,这样就行. location ^~ /d ...