Advertisement
HXXXXJ

836. Rectangle Overlap

Apr 11th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.46 KB | None | 0 0
  1.     func isRectangleOverlap(_ rec1: [Int], _ rec2: [Int]) -> Bool {
  2.         let top1 = rec1[0]
  3.         let top2 = rec2[0]
  4.         let left1 = rec1[1]
  5.         let left2 = rec2[1]
  6.         let right1 = rec1[3]
  7.         let right2 = rec2[3]
  8.         let bottom1 = rec1[2]
  9.         let bottom2 = rec2[2]
  10.        
  11.         if right1 <= left2 || right2 <= left1 || top1 >= bottom2 || top2 >= bottom1 {
  12.             return false
  13.         }
  14.         return true
  15.        
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement