这题很简单,一开始用了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的更多相关文章

  1. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  2. 【题解】【数组】【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- ...

  3. 【题解】【数组】【Prefix Sums】【Codility】Passing Cars

    A non-empty zero-indexed array A consisting of N integers is given. The consecutive elements of arra ...

  4. Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .

    例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...

  5. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  6. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  7. 1014: [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...

  8. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  9. codility flags solution

    How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...

  10. [BZOJ1014][JSOI2008]火星人prefix

    [BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...

随机推荐

  1. ajax调用服务的基本格式

    <个人积累,转载请注明出处> 格式如下: $.ajax({ type: "post", //访问WebService使用Post方式请求 url: "http ...

  2. Android——四种AterDialog

    本经验将分别介绍Android里面的四种AlertDialog分别是:显示带中立,取消,确定的提示框. 获取带列表的对话框按钮.获取带单选列表的对话框按.获取显示带多选项的对话框.此经验介绍获取显示带 ...

  3. Oracle归档已满的处理办法

    SqlPlus: / as sysdba select * from V$FLASH_RECOVERY_AREA_USAGE; show parameter log_archive_dest; sho ...

  4. css 盒子模型理解

    盒子模型是html+css中最核心的基础知识,理解了这个重要的概念才能更好的排版,进行页面布局.下面是自己积累和总结的关于css盒子模型的知识^_^,希望对初学者有用. 一.css盒子模型概念 CSS ...

  5. ASCII Table/ASCII表

    ASCII Table/ASCII表 参考: 1.Table of ASCII Characters

  6. 2016/7/7 自定义函数copy

    题目:输入整数n(n<=10000),表示接下来将会输入n个实数,将这n个实数存入数组a中.请定义一个数组拷贝函数将数组a中的n个数拷贝到数组b中. 分析: (1)输入n,再输入n个实数存入数组 ...

  7. Wix: Using Patch Creation Properties - Small Update

    Source Reference: wix help document  -- WiX Toolset License Using Patch Creation Properties  A patch ...

  8. Linux网络服务器epoll模型的socket通讯的实现(一)

    准备写一个网络游戏的服务器的通讯模块,参考网上看到的一些代码,在linux下面实现一个多线程的epoll模型的socket通讯的代码,以下是第一部分多线程的切换代码: 1 #include <s ...

  9. Arrays 标准库算法

    Binary Search public static int binarySearch0(Object[] a, int fromIndex, int toIndex, Object key) { ...

  10. QtSQL学习笔记(1)- 概述

    Qt SQL是Qt提供的核心模块,用以支持SQL数据库.Qt SQL的API被分为不同的层: ■ 驱动层 (Driver layer) ■ API层 (SQL API layer) ■ 用户接口层 ( ...