首页 > 其他分享 >leetcode-836-easy

leetcode-836-easy

时间:2023-03-11 13:46:36浏览次数:43  
标签:836 return easy Input rec2 false rec1 leetcode axis

Rectangle Overlap

An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.

Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.

Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.

Example 1:

Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output: true
Example 2:

Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output: false
Example 3:

Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]
Output: false
Constraints:

rec1.length == 4
rec2.length == 4
-109 <= rec1[i], rec2[i] <= 109
rec1 and rec2 represent a valid rectangle with a non-zero area.

思路一:判断 x 是否在重叠区间内

    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        return !(rec1[2] <= rec2[0] || rec1[3] <= rec2[1] || rec1[0] >= rec2[2] || rec1[1] >= rec2[3]);
    }

标签:836,return,easy,Input,rec2,false,rec1,leetcode,axis
From: https://www.cnblogs.com/iyiluo/p/17205769.html

相关文章

  • leetcode-1122-easy
    RelativeSortArrayGiventwoarraysarr1andarr2,theelementsofarr2aredistinct,andallelementsinarr2arealsoinarr1.Sorttheelementsofarr1su......
  • leetcode-1071-easy
    GreatestCommonDivisorofStringsFortwostringssandt,wesay"tdividess"ifandonlyifs=t+...+t(i.e.,tisconcatenatedwithitselfoneormor......
  • leetcode-1389-easy
    CreateTargetArrayintheGivenOrderGiventwoarraysofintegersnumsandindex.Yourtaskistocreatetargetarrayunderthefollowingrules:Initiallyt......
  • leetcode-1544-easy
    MakeTheStringGreatGivenastringsofloweranduppercaseEnglishletters.Agoodstringisastringwhichdoesn'thavetwoadjacentcharacterss[i]and......
  • leetcode-977-easy
    SquaresofaSortedArrayGivenanintegerarraynumssortedinnon-decreasingorder,returnanarrayofthesquaresofeachnumbersortedinnon-decreasingor......
  • leetcode-1021-easy
    RemoveOutermostParenthesesAvalidparenthesesstringiseitherempty"","("+A+")",orA+B,whereAandBarevalidparenthesesstrings,and+represe......
  • leetcode-1496-easy
    PathCrossingGivenastringpath,wherepath[i]='N','S','E'or'W',eachrepresentingmovingoneunitnorth,south,east,orwest,respectively.Youstart......
  • leetcode-1523-easy
    CountOddNumbersinanIntervalRangeGiventwonon-negativeintegerslowandhigh.Returnthecountofoddnumbersbetweenlowandhigh(inclusive).Example......
  • LeetCode|2457. 美丽整数的最小增量
    题目链接:2457.美丽整数的最小增量给你两个正整数n和target。如果某个整数每一位上的数字相加小于或等于target,则认为这个整数是一个美丽整数。找出并返回满......
  • 【LeetCode回溯算法#07】子集问题I+II,巩固解题模板并详解回溯算法中的去重问题
    子集力扣题目链接给你一个整数数组nums,数组中的元素互不相同。返回该数组所有可能的子集(幂集)。解集不能包含重复的子集。你可以按任意顺序返回解集。示例1:输......