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--分组数据
1.数据分组 #连接数据库 use newschema; #查看表中数据 select *from products: #返回供应商1003提供的产品数目 ; 2.创建分组 select vend_i ...
- 初撩Django-RESTful-rest_framework序列化(将模型序列化为JSON)
官方网站: https://www.django-rest-framework.org/ 翻译网站:https://q1mi.github.io/Django-REST-framework-docum ...
- 1、cmd中检测远程的ip和端口是否处于监听状态
一.使用 ping 命令测试远程的ip是否可连通 cmd (右键 管理员角色) --- ping IP 二.使用 telnet 测试远程某一个ip的端口是否开放 1.为了安全起见,window ...
- vue 学习七 组件上使用插槽
我们有时候可能会在组件上添加元素,就像下面那样 <template> <div id="a"> <com1> <p>我是渲染的值&l ...
- vue组件参数校验与非props特性
组件参数校验 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- Linux服务器查看PHP是否支持mail()函数方法
PHP的Mail函数可以用来发送邮件,如查看Linux服务器PHP是否支持Mail函数? PHP查看是否支持Mail函数的方法 Linux系统下的服务器,查看PHP是否支持Mail函数的方法有很多种: ...
- bypass_safedog
1.SQL注入 手工bypass要点 先通过破坏关键字测试出拦截规则 之后进行针对性绕过 1.Mysql 1.1.联合注入 0x01 and绕过 直接 and 1=1 直接就会被拦截 在数值的前面加特 ...
- 前端agl分页的写法
<!-- 分页组件开始 --> <script src="../plugins/angularjs/pagination.js"></script&g ...
- vscode开发vue项目保存时自动执行lint进行修复
vscode下载eslint插件 vscode进行设置 找到settings.json 在里面写入如下内容进行保存 { "eslint.autoFixOnSave": tr ...
- 大牛公司的github
Google Google https://github.com/google Google Samples https://github.com/googlesamples Google Codel ...