1 Star 0 Fork 0

agony/LeetCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
223.RectangleArea.cs 585 Bytes
一键复制 编辑 原始数据 按行查看 历史
Kai Yang 提交于 2015-06-08 13:54 . 223. Rectangle Area
// https://leetcode.com/problems/rectangle-area/
using System;
public partial class Solution
{
public int ComputeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
var area = (long)(C - A) * (D - B) + (G - E) * (H - F);
var overlapA = Math.Max(A, E);
var overlapB = Math.Max(B, F);
var overlapC = Math.Min(C, G);
var overlapD = Math.Min(D, H);
if (overlapA < overlapC && overlapB < overlapD)
{
area -= (overlapC - overlapA) * (overlapD - overlapB);
}
return (int)area;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/agony2020/LeetCode.git
git@gitee.com:agony2020/LeetCode.git
agony2020
LeetCode
LeetCode
master

搜索帮助