【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
思路:简单题用set
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> myset;
for(int i = ; i < nums.size(); ++i)
{
if(myset.find(nums[i]) != myset.end())
return true;
myset.insert(nums[i]);
}
return false;
}
Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Assume that the total area is never beyond the maximum possible value of int.
思路:求总面积。直观解法。简单题。
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int up = min(D, H);
int down = max(B, F);
int left = max(A, E);
int right = min(C, G);
int In = (up > down && right > left) ? (up - down) * (right - left) : ;
int area1 = (C - A) * (D - B);
int area2 = (G - E) * (H - F);
return area1 + area2 - In;
}
【leetcode】Contains Duplicate & Rectangle Area(easy)的更多相关文章
- 【leetcode】Merge Two Sorted Lists(easy)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- 【leetcode】Remove Linked List Elements(easy)
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- 【LeetCode】120. Triangle 解题报告(Python)
[LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址htt ...
- 【LeetCode】10.Regular Expression Matching(dp)
[题意] 给两个字符串s和p,判断s是否能用p进行匹配. [题解] dp[i][j]表示s的前i个是否能被p的前j个匹配. 首先可以分成3大类情况,我们先从简单的看起: (1)s[i - 1] = p ...
- 【leetcode】Search for a Range(middle)
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- 【LeetCode】51. N-Queens 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...
- 【LeetCode】274. H-Index 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/h-index/ ...
- 【LeetCode】389 Find the Difference(java)
原题 Given two strings s and t which consist of only lowercase letters. String t is generated by rando ...
- 【leetcode】Swap Nodes in Pairs (middle)
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
随机推荐
- 包装类(Wrapper Class)
1)包装类.针对于原生数据类型的包装.所有的包装类(8个)对位于java.lang包下.java中的8个包装类分别是:Byte,Short,Integer,Long,Float.Double,Char ...
- oracle 日志文件管理
OS: [root@b28-122 ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 DB: SQL> select * f ...
- 【转】oracle connect by用法
今天偶然看到connect by,但记不太清楚具体用法了.转了个博客(写的蛮好的),当作笔记. http://www.cnblogs.com/linjiqin/p/3152690.html 先用sco ...
- MySQL 设置允许远程登录
1.修改数据表 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在 localhost 的那台电脑,登入MySQL后,更改 "MySQL" 数据库里的 &qu ...
- asp.net实现手机号码归属地查询,代码如下
protected void Button1_Click(object sender, EventArgs e) { if (Regex.IsMatch(TextB ...
- Go append方法
append用来将元素添加到切片末尾并返回结果.看代码: package main import "fmt" func main() { x := [],,} y := [],,} ...
- [转]linux时间同步
转自:http://www.jotop.com/2012/vpsinfo_0525/439.html 美国的vps大多都是国外的时间,让我们的程序总是不适应.那么如何调整linux的时间为北京时间?修 ...
- SQL-LINQ-Lambda语法对照,好记性不如烂笔头
忘记的时候就翻阅翻阅吧~~ SQL LINQ Lambda SELECT *FROM HumanResources.Employee from e in Employees select e Empl ...
- Labview实现单边带信号调制(SSB)[移相法]
Labview实现单边带信号调制(SSB)[移相法] 时域上的表达式为 调制器模型为 这个实验中需要相位偏移比较多,因为一共用了四个信号仿真器,一个是无偏移的调制信号,一个是偏移的调制信号,一个是无偏 ...
- disable_irq()与disable_irq_nosync()区别
disable_irq关闭中断并等待中断处理完后返回, 而disable_irq_nosync立即返回.