leetcode-159周赛-5230-缀点成线

自己的提交:
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-缀点成线的更多相关文章
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- 【LeetCode】To Lower Case(转换成小写字母)
这道题是LeetCode里的第709道题. 题目要求: 实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: ...
- LeetCode 709. To Lower Case (转换成小写字母)
题目标签:String 题目让我们把大写字母转换成小写,只要遇到的是大写字母,把它 + 32 变成 小写就可以了. Java Solution: Runtime beats 100.00% 完成日期: ...
- [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 ...
- LeetCode随缘刷题之转化成小写字母
这道题应该是最简单的一道题了把,简直在侮辱我. package leetcode.day_12_12; /** * 709. 转换成小写字母 * 给你一个字符串 s ,将该字符串中的大写字母转换成相同 ...
- [LeetCode] Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- IT关键词,发现与更新,点成线,线成面,面成体
时序图 1.什么是时序图 2.如何看懂时序图 3.时序图的作用 4.如何绘制时序图 分布式 一个业务分拆多个子业务,部署在不同的服务器上. 分布式是指将不同的业务分布在不同的地方. 而集群指的是将几台 ...
- ✡ 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 ...
- [leetcode]131. Palindrome Partitioning字符串分割成回文子串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
随机推荐
- MySQL索引与事务
MySQL索引与事务 链接:https://pan.baidu.com/s/1ANGg3Kd_28BzQrA5ya17fQ 提取码:ekpy 复制这段内容后打开百度网盘手机App,操作更方便哦 1.索 ...
- 解决Zookeeper报错:conf is not executed because it is not in the whitelist的解决办法
1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [root@xg61 ...
- elasticsearch学习笔记001
<Elasticsearch 核心技术与实战>课程Github代码 https://github.com/onebirdrocks/geektime-ELK 运行的环境: windows ...
- Cesium指南针
cesium里面没有指南针 需要安装其他的插件: cesium-navigation-es6 npm i cesium-navigation-es6 -S 安装好之后在mainjs里引入 import ...
- SparkSQL(一)
一.概述 组件 运行机制 转 SparkSQL – 从0到1认识Catalyst https://blog.csdn.net/qq_36421826/article/details/81988157 ...
- 【专业的 Markdown 编辑写作软件】MWeb for Mac基本使用教程
MWeb for Mac是一款专业的 Markdown 编辑写作软件,可以生成MarkDown编辑器和静态博客,在记日记的时候,你可以使用插入图片的功能,使用MWeb软件你可以拖拽或直接粘贴即可插入图 ...
- luoguP1313 [NOIp2011]计算系数 [组合数学]
题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k , ...
- 模拟+细节题——cf1236D
思路好想,细节多的令人发指.. /* 反着判断:走完每个点=走过的路程=n*m-k 然后暴力判每行每列的目的地 每次走都能使走的范围缩小一行或者一列 */ #include<bits/stdc+ ...
- EXCEL2016 OLE/COM开发-常用功能封装代码
hpp #pragma once #include "stdafx.h" #include "CApplication.h" #include "CW ...
- Jquery里live事件移除原因
live()事件 $('a').live('click', function() { alert("That tickles!") }); live事件Jq把alert函数绑定到$ ...