223. Rectangle Area
蠢错误翻得够够的。
注意的地方就是,有可能并没有overlap
下次一定要看清题目。
注意变量的scope.
注意返回
1 public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { 2 int overlap = 0; 3 if((E < C && F < D) && (G > A && H > B)) { 4 int I = Math.max(A, E); 5 int J = Math.max(B,F); 6 int K = Math.min(C,G); 7 int L = Math.min(D,H); 8 overlap = (K - I) * (L - J); 9 } 10 System.out.println(overlap); 11 return (C - A) * (D - B) + (G - E) * (H - F) - overlap;