首页 > 其他分享 >【LeetCode】第48天 - 1037. 有效的回旋镖

【LeetCode】第48天 - 1037. 有效的回旋镖

时间:2022-12-06 10:38:21浏览次数:56  
标签:48 int 1037 points 回旋 y1 y2 LeetCode 向量


1037. 有效的回旋镖

  • ​​题目描述​​
  • ​​解题思路​​
  • ​​代码实现​​

题目描述

【LeetCode】第48天 - 1037. 有效的回旋镖_1037

解题思路

没想到遇到一道纯数学题。

所谓的“有效的回旋镖”就是指所给的三个点不在同一条直线上。

  • 由三个点可以计算得到两个向量
  • 三个点不在同一条直线上,即两个向量不平行,即叉乘不为0。

代码实现

class Solution {
public boolean isBoomerang(int[][] points) {
//计算第一个向量
int x1=points[1][0]-points[0][0],y1=points[1][1]-points[0][1];
//计算第二个向量
int x2=points[2][0]-points[0][0],y2=points[2][1]-points[0][1];

//向量叉乘不为0
return (x1*y2-x2*y1)!=0;
}
}


标签:48,int,1037,points,回旋,y1,y2,LeetCode,向量
From: https://blog.51cto.com/u_15901218/5914769

相关文章

  • [LeetCode] 1805. Number of Different Integers in a String
    Youaregivenastring word thatconsistsofdigitsandlowercaseEnglishletters.Youwillreplaceeverynon-digitcharacterwithaspace.Forexample, "a1......
  • [LeetCode] 2270. Number of Ways to Split Array
    Youaregivena 0-indexed integerarray nums oflength n.nums containsa validsplit atindex i ifthefollowingaretrue:Thesumofthefirst i......
  • leetcode 1687. 从仓库到码头运输箱子 动态规划 + 单调队列
    你有一辆货运卡车,你需要用这一辆车把一些箱子从仓库运送到码头。这辆卡车每次运输有 箱子数目的限制 和总重量的限制 。给你一个箱子数组 boxes 和三个整数portsCo......
  • LeetCode刷题记录.Day32
    翻转二叉树递归法classSolution{public:TreeNode*invertTree(TreeNode*root){if(root==nullptr)returnroot;swap(root->left,root->......
  • LeetCode397. Integer Replacement
    题意一个数n,若为偶数,则除2,若为奇数,则加减1;求其最终为1,需要几步方法位运算代码classSolution{public:intintegerReplacement(intn){i......
  • [Leetcode Weekly Contest]322
    链接:LeetCode[Leetcode]2490.回环句句子是由单个空格分隔的一组单词,且不含前导或尾随空格。例如,"HelloWorld"、"HELLO"、"helloworldhelloworld"都是符合要求的......
  • LeetCode: 290. Word Pattern
    LeetCode:290.WordPattern题目描述Givena​​pattern​​​andastring​​str​​​,findif​​str​​​followsthesame​​pattern​​.Herefollowmea......
  • LeetCode: 310. Minimum Height Trees
    LeetCode:310.MinimumHeightTrees题目描述Foranundirectedgraphwithtreecharacteristics,wecanchooseanynodeastheroot.Theresultgraphisthenaro......
  • LeetCode: 312. Burst Balloons
    LeetCode:312.BurstBalloons题目描述Givennballoons,indexedfrom0ton-1.Eachballoonispaintedwithanumberonitrepresentedbyarraynums.Youareas......
  • LeetCode: 328. Odd Even Linked List
    LeetCode:328.OddEvenLinkedList题目描述Givenasinglylinkedlist,groupalloddnodestogetherfollowedbytheevennodes.Pleasenoteherewearetalking......