[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,我们将这个字符串的各个字 ...
随机推荐
- Activiti源码浅析:Activity与Task
最近由于接触到Activiti工作流引擎,因此粗读了一下它的源码. 总结了一些内容如下,这些内容一般的doc上都是没有提及的. 1. model.Activity与model.Task Activit ...
- android体系架构
android体系架构总结: android体系架构分为四层 第一层:应用层:applications 第二层:开发层 第三层:
- 常用Linux/Unix/Mac Os命令
常用Linux/Unix/Mac OS命令 参考: 1.50 Most Frequently Used UNIX / Linux Commands (With Examples)
- 学习C++ Primer 的个人理解(十一)
关联容器 就像是个字典, 其元素是 键 - 值 对. 关键字起到索引作用. 有序: map:关联数组:保存 健-值 对 set : 关键字既是值. multimap : 关键字可重复出现的map mu ...
- config spec
config_spec Rules for selecting versions of elements to appear in a view APPLICABILITY Product Comma ...
- Eclipse配置CAS server
1.下载cas server的源码包(我使用的是cas-server-3.5.2.1-release.zip) 2.解压压缩包到某个目录下,找到cas-server-3.5.2.1-release.z ...
- msyql判断记录是否存在的三种方法
1. select count(*) from .... 这种方法最常见但是效率比较低,因为它需要扫描所有满足条件的记录 2. select 1 from xxxtable where .... 这种 ...
- linux(centos)搭建svn
1.yum install subversion 2.输入rpm -ql subversion查看安装位置 输入 svn --help可以查看svn的使用方法 3.创建svn版本库目录 mkdir - ...
- php中的修饰符
上面使用了一个修饰符U,详见关于修饰符的介绍. PHP正则表达式修饰符的理解: 在PHP正则表达式里面的修饰符可以改变正则的很多特性,使得正则表达式更加适合你的需要(注意:修饰符对于大小写是敏感的,这 ...
- Python开发轻量级爬虫
这两天自学了python写爬虫,总结一下: 开发目的:抓取百度百科python词条页面的1000个网页 设计思路: 1,了解简单的爬虫架构: 2,动态的执行流程: 3,各部分的实现: URL管理器:p ...