Find file History
Latest commit bfc8da4 Jul 25, 2016 @xuelangZF update 42, 43, 44, 45
Permalink
..
Failed to load latest commit information.
07_ReverseInteger.py Delete directory Week01, move solutions in Week01 to maching Tags Oct 20, 2015
09_PalindromeNumber.cpp
09_PalindromeNumber.py add 09 cpp and update some py May 6, 2016
12_IntegertoRoman.py
13_RomantoInteger.py
166_FractionToRecurringDecimal.py
168_ExcelSheetColumnTitle.py add 168, 169, 166, 171 Dec 7, 2015
171_ExcelSheetColumnNumber.py
172_FactorialTrailingZeroes.py
179_LargestNumber.py
202_HappyNumber.py
204_CountPrimes.py
223_RectangleArea.cpp add math readme and 223 Apr 12, 2016
223_RectangleArea.py
233_NumberOfDigitOne.cpp update 233 Apr 28, 2016
233_NumberOfDigitOne.py
238_ProductOfArrayExceptSelf.py add 236, 237, 238, 239 Jan 21, 2016
258_AddDigits.py add 242, 258 Jan 22, 2016
263_UglyNumber.cpp update 264 UglyNumber cpp Apr 15, 2016
263_UglyNumber.py update 264 UglyNumber cpp Apr 15, 2016
273_IntegerToEnglishWords.py add 268, 273, 274, 275 Jan 25, 2016
292_NimGame.py
319_BulbSwitcher.py
326_PowerOfThree.py
335_SelfCrossing.py
343_IntegerBreak.cpp
343_IntegerBreak.py
43_MultiplyStrings.cpp
43_MultiplyStrings.py update 42, 43, 44, 45 Jul 26, 2016
48_RotateImage.cpp
48_RotateImage.py add 48 RotateImage Jun 12, 2016
50_Pow.cpp
50_Pow.py
60_PermutationSequence.cpp add Permutation Sequence Jun 28, 2016
60_PermutationSequence.py
66_PlusOne.py links to the source code in README.md Nov 4, 2015
README.md

README.md

题目

223 Rectangle Area

计算平面坐标系中两个矩形覆盖的面积。注意两个矩形有可能相交,相交部分面积只能算一次,其中给出了每个矩形的左下角和右上角的坐标。

下图为矩形的可能情况:

解决问题关键在于假设矩形相交,然后找出重合的小矩形的左下角坐标和右上角坐标,判断这两个坐标是否能够构成矩形。

// 假设两个矩形相交,重合矩形的坐标如下
int left = max(A, E);
int bottom = max(B, F);
int right = min(C, G);
int top = min(D, H);

矩形相交的条件为 left < right && bottom < top