【LeetCode】1037. Valid Boomerang 解题报告(C++)
作者: 负雪明烛
id: fuxuemingzhu
个人博客: http://fuxuemingzhu.cn/
题目地址:https://leetcode.com/problems/valid-boomerang/
题目描述
A 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:
points.length == 3
points[i].length == 2
0 <= points[i][j] <= 100
题目大意
判断三个点是否不重叠,并且不在一个直线上。
解题方法
中学数学题
不重叠很好说,三个点两两判断即可。
判断三个点是不是在一个直线上,那么三个点中任意两个点的连线之斜率是否相等(或者不存在)。用数学公式表示就是dx1 * dy2 == dx2 * dy1则在一条直线上。
C++代码如下:
class Solution {
public:
bool isBoomerang(vector<vector<int>>& points) {
if (points[0][0] == points[1][0] && points[0][1] == points[1][1])
return false;
if (points[0][0] == points[2][0] && points[0][1] == points[2][1])
return false;
if (points[1][0] == points[2][0] && points[1][1] == points[2][1])
return false;
int dx1 = points[1][0] - points[0][0];
int dy1 = points[1][1] - points[0][1];
int dx2 = points[2][0] - points[1][0];
int dy2 = points[2][1] - points[1][1];
return dx1 * dy2 != dx2 * dy1;
}
};
日期
2019 年 8 月 31 日 —— 赶在月底做个题
【LeetCode】1037. Valid Boomerang 解题报告(C++)的更多相关文章
- LeetCode: Longest Valid Parentheses 解题报告
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...
- LeetCode 1037. Valid Boomerang (有效的回旋镖)
题目标签:Math 题目给了我们三个点,让我们判断这三个点是否在一条直线上. 利用斜率 k = (y1 - y0) / (x1 - x0) 来判断,如果 三个点 abc, ab 的斜率 = bc 的斜 ...
- LeetCode 242 Valid Anagram 解题报告
题目要求 Given two strings s and t , write a function to determine if t is an anagram of s. 题目分析及思路 给出两个 ...
- 【LeetCode】36. Valid Sudoku 解题报告(Python)
[LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【Leetcode_easy】1037. Valid Boomerang
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完
- 【LeetCode】Island Perimeter 解题报告
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...
随机推荐
- 小程序https启用tls1.2
公司的web服务器是iis7,在开发微信小程序的时候,需要启用TLS1.2. 将下面的代码复制到文本,存为reg文档,双击搞定. Windows Registry Editor Version 5.0 ...
- springcloud - alibaba - 2 - 集成Feign - 更新完成
1.依赖 依赖管理 <parent> <artifactId>spring-boot-parent</artifactId> <groupId>org. ...
- keras房价预测数据集boston_housing.npz文件下载
github地址: https://github.com/yuxiwang66/boston_housing 码云地址: https://gitee.com/polarisslk/boston_hou ...
- Shell $()、${}、$[]、$(())
目录 Shell中的 $().${}.$[].$(()) $().${} 替换 ${} 变量内容的替换.删除.取代 数组 $[].$(()) 运算符 Shell中的 $().${}.$[].$(()) ...
- day06 模板层
day06 模板层 今日内容 常用语法 模板语法传值 模板语法之过滤器 模板语法之标签 自定义过滤器.标签.inclusion_tag(BBS作业用一次) 模板的继承(django前后端结合 那么使用 ...
- 零基础学习java------day27-28---------电影评分数据案例,. RPC案例
一. 电影评分数据案例 movie:电影id rate:用户评分 timeStamp:评分时间 uid:用户id 简化数据: 需求: (1)每个用户评分最高的3部电影 (2)每个用户评分的平均值 ( ...
- NuxtJS的AsyncData和Fetch使用详解
asyncData 简介 asyncData 可以用来在客户端加载 Data 数据之前对其做一些处理,也可以在此发起异步请求,提前设置数据,这样在客户端加载页面的时候,就会直接加载提前渲染好并带有数据 ...
- Initialization of data members
In C++, class variables are initialized in the same order as they appear in the class declaration. C ...
- 『学了就忘』Linux启动引导与修复 — 72、Linux系统的修复模式(单用户模式)
目录 1.单用户模式常见的错误修复 2.通过单用户模式修改系统密码 (1)进入grub启动引导程序中 (2)编辑相应的系统启动内容 (3)编辑grub配置文件内容 (4)启动系统 (5)修改root用 ...
- 什么是API?
一.简介 API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序,与开发人员基于某软件或硬件得以访问一组例程的能力,而又 ...