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)的更多相关文章

  1. 【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 ...

  2. 【leetcode】Remove Linked List Elements(easy)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  3. 【LeetCode】120. Triangle 解题报告(Python)

    [LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址htt ...

  4. 【LeetCode】10.Regular Expression Matching(dp)

    [题意] 给两个字符串s和p,判断s是否能用p进行匹配. [题解] dp[i][j]表示s的前i个是否能被p的前j个匹配. 首先可以分成3大类情况,我们先从简单的看起: (1)s[i - 1] = p ...

  5. 【leetcode】Search for a Range(middle)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  6. 【LeetCode】51. N-Queens 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  7. 【LeetCode】274. H-Index 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/h-index/ ...

  8. 【LeetCode】389 Find the Difference(java)

    原题 Given two strings s and t which consist of only lowercase letters. String t is generated by rando ...

  9. 【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 ...

随机推荐

  1. .net控件事件中的Sender

    private void button2_Click(object sender, RoutedEventArgs e) { } 最近看WPF内容,回顾下.net大家天天都在用,却不是十分关注的一个对 ...

  2. 刀哥多线程全局队列gcd-09-global_queue

    全局队列 是系统为了方便程序员开发提供的,其工作表现与并发队列一致 全局队列 & 并发队列的区别 全局队列 没有名称 无论 MRC & ARC 都不需要考虑释放 日常开发中,建议使用& ...

  3. 刀哥多线程串行队列gcd-04-dispatch_queue_serial

    串行队列 特点 以先进先出的方式,顺序调度队列中的任务执行 无论队列中所指定的执行任务函数是同步还是异步,都会等待前一个任务执行完成后,再调度后面的任务 队列创建 dispatch_queue_t q ...

  4. python2 编码问题详解

    实例对比 定义 type str unicode print encode('utf8') decode('utf8') encode('unicode-escape') encode('string ...

  5. hdu 1212 Big Number

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Big Number Description As we know, Big Number is ...

  6. 请输入正确的RSA公钥

    没啥原因,换个浏览器就好使,原因是现有窗口登陆超时了.

  7. Knockout.Js学习目录

    1.Knockout.Js(简介) 2.Knockout.Js(监控属性Observables) 3.Knockout.Js(属性绑定) 4.Knockout.Js(事件绑定) 5.Knockout. ...

  8. b75,gtx560,I5 安装10.10.2

    1.安装变色龙,wowpc.iso,这个是可以让电脑从windows引导 mac 安装的. 2.把黑苹果CDR压到一个硬盘分区里去. 3.安装10.10.2,把安装盘里的extra拷贝到 系统盘里 , ...

  9. c/c++常用代码 -- 共享内存

    #pragma once #include <stdio.h> #include <tchar.h> #include <string.h> #include &l ...

  10. 宣讲ppt的技巧

    这是一个L运营商的项目,项目规模比较大,中兴的客户群体定位主要是电信运营商,运营商的项目做起来非常累,不是一般的小公司能玩的,一般项目要经过这几个过程,前期信息获得——技术交流引导——实验局测试——投 ...