[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,我们将这个字符串的各个字 ...
随机推荐
- 一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确
一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确 最近没事研究了下验证码的的动态生成及通过cookie实现HTML页面对用户输入的验证码的校验,简要如下: 1.写 ...
- 20160515-hibernate--事务
事务 JDBCTransaction 单个数据库(一个SesisonFactory对应一个数据库),由JDBC实现. Session session = null; Transaction tx =n ...
- Android更改桌面应用程序launcher的两种方式
http://blog.csdn.net/mdx20072419/article/details/9632779/ launcher,也就是android的桌面应用程序.下图是我正在使用的魅族手机的l ...
- selenium简单代码入门
#!/usr/bin/env python #-*- coding:utf-8 -*- import os,sys,string import time import unittest from se ...
- XIB 不能拖线的低级错误
问题描述 创建 XIB 文件后,与其相关联的.m文件进行拖线,但无论如何都无法拖线,过程无任何反应.清除缓存重启 Xcode 均无法解决. 解决方法 事实上这是个低级错误,原因为 xib 的 view ...
- Android--LowMemoryKiller知识点补充
Android在内存管理上与linux有些小的区别.其中一个就是引入了Low memory killer . 1.引入原因: Android是一个多任务系统,也就是说可以同时运行多个程序,这个大家应该 ...
- ios -- cell的图片下载
1.面试题 1> 如何防止一个url对应的图片重复下载 * “cell下载图片思路 – 有沙盒缓存” 2> SDWebImage的默认缓存时长是多少? * 1个星期 3> SDWeb ...
- C#上传图片和生成缩略图以及图片预览
因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...
- Putty + Vim + Color
Putty + Vim + Color 参考: 1.Using colour schemes with vim and putty 2.Putty的颜色 3.Custom PuTTY Color Th ...
- C# 调用load事件
在一个函数或者事件中调用另外的事件,例如调用Load事件 private void EventForm_Load(object sender, EventArgs e) { //相关内容 } priv ...