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

  1. bool containsDuplicate(vector<int>& nums) {
  2. unordered_set<int> myset;
  3. for(int i = ; i < nums.size(); ++i)
  4. {
  5. if(myset.find(nums[i]) != myset.end())
  6. return true;
  7. myset.insert(nums[i]);
  8. }
  9. return false;
  10. }

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.

思路:求总面积。直观解法。简单题。

  1. int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
  2. int up = min(D, H);
  3. int down = max(B, F);
  4. int left = max(A, E);
  5. int right = min(C, G);
  6. int In = (up > down && right > left) ? (up - down) * (right - left) : ;
  7. int area1 = (C - A) * (D - B);
  8. int area2 = (G - E) * (H - F);
  9.  
  10. return area1 + area2 - In;
  11. }

【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. 使用工厂bean和Utility Schema定义集合

    工厂bean是实现了beanFactory接口的bean,也可以继承AbstractFactoryBean,主要是用于在给定属性参数之后自动创建一个bean对象. 我们在使用基本集合标记定义集合时,不 ...

  2. libcurl 安装使用一

    一.下载libcurl http://curl.haxx.se/download/curl-7.21.1.tar.gz 二.安装   指定了安装目录     /usr/local/curl 命令1: ...

  3. Oracle 11gR2 Database和Active Data Guard迁移案例

    客户一套核心系统由一台Oracle Database 11.2.0.3.4单机和一台Active Data Guard组成,分别运行在两台PC服务器上,Oracle Linux 5.8 x86_64b ...

  4. iOS学习之UI可视化编程-XIB

    一.Interface Builder可视化编程 1.Interface Builder简介: GUI:图形用户界面(Graphical User Interface,简称GUI,又称图形用户接口)是 ...

  5. SoapUI-x64(app:url请求参数)

    SoapUI-x64-5.2.0_576025

  6. “psp”软件需求规约

    1 系统概述 1.1 概述 该产品是基于软件开发的个人软件过程(personal software process)系统.基本信息有软件开发人员,项目经理,研发经理和管理层登录系统后根据各自的相应权限 ...

  7. forword属性

    forword属性 2013年7月8日 15:07 Name: Forward的名字,与mapping.findForward方法传入的值相同. Path: 请求转发的页面路径 Redirect: 请 ...

  8. [DHCP服务]——一个验证DHCP原理实验(VMware)

    大致实验拓扑图 DHCP Server端的配置 1. 安装DHCP # yum -y install dhcp 2. 拷贝配置文件 # /dhcpd.conf.sample /etc/dhcp/dhc ...

  9. 安装ubuntu时将boot目录单独挂载的意义

    只有一个意义那就是当你的情况是:单个硬盘里面安装多个系统. 如果不是这样,就别动它.

  10. ostream类重载的operator<<()函数

    ostream类重载了operator<<()以识别不同的类型,如: int short  long unsigned int unsigned short unsigned long f ...