【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 ...
随机推荐
- NOJ1103-全排列
全排列 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 1148 测试通过 : 302 ...
- spring AOP advice 类型 和 通用的切点的配置方式
spring aop advice的类型: 1.前置通知(before advice) 2.返回后通知(after returning advice) 3.抛出异常后通知(after throwing ...
- jdbc 连接 oracle rac
jdbc 连接 oracle rac 的连接串如下: jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192. ...
- android开发系列之由ContentValues看到的
这本篇博客里面我想重点来分析一下ContentValues的源码以及它里面涉及到的继承接口Parcelabel,还有HashMap的源码. 相信使用过android里面数据库操作的朋友对于Conten ...
- squid基础配置
1 2 3 4 5 6 7 8 9 10 vim /etc/squid/squid.conf http_port 192.168.1.12:3128 (可写多个) cache_mem 64MB ...
- shell 编程基础
1 创建shell脚本文件 要创建一个shell脚本文件,必须在第一行指定要使用的shell,其格式为: #! /bin/bash 接着加上该shell文件的注释,说明该脚本文件用来干什么,有谁创建, ...
- 华硕电脑安装ubuntu出现问题及决方案
问 题 一:华硕电脑安装ubuntu时无线网络禁用解决方案:打开终端(Ctrl+alt+t)运行命令sudo rmmod acer-wmi,然后开启无线,连接上后便可以上网(附上ubuntu论坛上讨论 ...
- (转)Unity3D游戏开发 NGUI之渐变加载到100%的Loading场景进度条
NGUI 现有的进度条存在的问题: 进度条跳跃式前进,加载到90%后卡住,突然进入下一个场景.接下来就是解决这个问题. 背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问 ...
- NET Core静态文件的缓存方式
NET Core静态文件的缓存方式 阅读目录 一.前言 二.StaticFileMiddleware 三.ASP.NET Core与CDN? 四.写在最后 回到目录 一.前言 我们在优化Web服务的时 ...
- Leetcode Variant-Plus N
Given a non-negative number represented as an array of digits, plus N to the number. The digits are ...