[LeetCode] Determine if two rectangles overlap
来源:互联网 发布:四小票采集软件 编辑:程序博客网 时间:2024/05/31 19:04
Given two axis-aligned rectangles A and B. Write a function to determine if the two rectangles overlap.
从问题的反面入手,先看看什么情况下两个长方形不重叠。
不重叠的条件是:( P2.y < P3.y || P1.y > P4.y || P2.x < P3.x || P1.x > P4.x )
直接给代码:
struct Point{ int x, y;}; // Returns true if two rectangles (l1, r1) and (l2, r2) overlapbool doOverlap(Point l1, Point r1, Point l2, Point r2){ // If one rectangle is on left side of other if (l1.x > r2.x || l2.x > r1.x) return false; // If one rectangle is above other if (l1.y < r2.y || l2.y < r1.y) return false; return true;}
0 0
- [LeetCode] Determine if two rectangles overlap
- determine if it is a power of two.
- Given two (dictionary) words as Strings, determine if they are isomorphic
- How to Determine if Two Words Are Anagrams of Each Other in C# (转)
- Given an integer, write a function to determine if it is a power of two.
- Given an integer, write a function to determine if it is a power of two
- Given two strings s and t, write a function to determine if t is an anagram of s.
- Given two strings s and t, write a function to determine if t is an anagram of s.
- 【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle
- How to determine if running on Emulator?
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- Detect whether two rectangles have common area or not -- Amazon
- Determine if a user's Session is still active
- How to determine if a machine is localhost?
- Linux(Ubuntu) 安装mysql,windows使用Navicat 连接
- 关于Mac的快捷操作
- Gray Code Leetcode Python
- 怎样在软件中使用apache license
- 90. Subsets II Leetcode Python
- [LeetCode] Determine if two rectangles overlap
- Ruby Notes
- 【BZOJ 1013】 [JSOI2008]球形空间产生器sphere
- C/C++中各种类型int、long、double、char表示范围(最大最小值)
- knockout.js
- Fragment学习
- 32位汇编语言学习笔记(42)--测试时间相关函数
- HDU2071 Max Num【水题】
- BZOJ 3439 Kpm的MC密码 Trie+可持久化线段树