[codility]Prefix-set
这题很简单,一开始用了set。但后来一想这样其实是n*logn的,而且没有利用所有的数都在0..N-1之间。那么可以直接用vector当hashset。
// you can also use includes, for example:
// #include <algorithm>
int solution(const vector<int> &A) {
// write your code in C++98
vector<bool> hashset;
int n = A.size();
hashset.resize(n, false);
int cover = -1;
for (int i = 0; i < n; i++) {
if (!hashset[A[i]]) {
cover = i;
hashset[A[i]] = true;
}
}
return cover;
}
[codility]Prefix-set的更多相关文章
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- 【题解】【数组】【Prefix Sums】【Codility】Genomic Range Query
A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper- ...
- 【题解】【数组】【Prefix Sums】【Codility】Passing Cars
A non-empty zero-indexed array A consisting of N integers is given. The consecutive elements of arra ...
- Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .
例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...
- 1014: [JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- [BZOJ1014][JSOI2008]火星人prefix
[BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...
随机推荐
- 在C#中创建类型
重载构造函数: using System; public class Wine { public decimal Price; public int Year; public Wine (decima ...
- java基础之Java变量命名规范
本文介绍的是java中的变量的命名规则,对于初学者来说,还是很重要的.希望对你有帮助,一起来看. Java是一种区分字母的大小写(case-sensitive)的语言,下面谈谈Java语言中包.类.变 ...
- 使用PHP连接、操纵Memcached的原理和教程
http://www.crazyant.net/1014.html Memcahced开源分布式内存对象缓存系统通过减少数据库的负担,从而能够加速你的web应用.在本文中我将解释怎样实现一个基于Mem ...
- 代码静态分析工具PCLint, Splint
一.PCLint REFER: 代码静态检查工具PC-Lint运用实践 二.Splint 1.在PC-Linux上安装 ①make error undefined reference toyywrap ...
- English Audio-Books
Downloadble English Audio-Books websites 一.网站 1.可听书 2.山寨 3.有声书库 4.audioboom.com 5.豆瓣小站 6.AudioBook 二 ...
- STL的简介
Standard Template Library,(标准模板库)<来自百度百科的整理> ————可复用性(reusability) STL是基于模板,内联函数的使用使得生成的代码短小高效 ...
- 九度OJ 1214 寻找丑数【算法】
题目地址:http://ac.jobdu.com/problem.php?pid=1214 题目描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因 ...
- MySQL 数据库增量数据恢复案例
MySQL 数据库增量数据恢复案例 一.场景概述 MySQL数据库每日零点自动全备 某天上午10点,小明莫名其妙地drop了一个数据库 我们需要通过全备的数据文件,以及增量的binlog文件进行数据恢 ...
- phpstudy 下开启openssl
1.在php.ini里面的extension=php_openssl.dll是开启的状态,没有被注释. 2.里面的allow_url_fopen = On表示开启了. 3.如果你是Windows 64 ...
- scroll
var fScrollTopHeight = function(){ return document.documentElement&&document.documentElement ...