[codility] Lesson 2

FrogRiverOne

def solution(X, A):
    positions = set()
    for i in range(len(A)):
        if A[i] not in positions:
            positions.add(A[i])
        if len(positions) == X:
            return i
    return -1
时间: 2024-11-08 20:32:14

[codility] Lesson 2的相关文章

Solution of Codility

Solution of Codility codility.com is another great place to improve your programming skill. Train myself , and record here. Lesson 1: Time Complexity Lesson 2: Counting Elements Lesson 3: Prefix Sums Lesson 4: Sorting MaxProductOfThree: * Distinct: *

Solution to Triangle by Codility

question: https://codility.com/programmers/lessons/4 we need two parts to prove our solution. on one hand, there is no false triangular. Given the array has been sorted, if A[i]+A[i+1]>A[i+2], we can prove the existence of the triangle. for array A i

[小北De编程手记] : Lesson 08 - Selenium For C# 之 PageFactory & 团队构建

本文想跟大家分享的是Selenium对PageObject模式的支持和自动化测试团队的构建.<Selenium For C#>系列的文章写到这里已经接近尾声了,如果之前的文章你是一篇篇的读下来并动手实践的话,我相信你应该可以模拟日常工作中80%常见的手动测试用例了.请注意:我的用词是模拟用例,而不是书写自动化测试用例.一个企业级的自动化测试的构建不是单靠Selenium一种技术就能Hold住的.所谓模拟指的是只能实现自动化的某个Case,但是不能工程化的使用.在本人所接触过几家公司的自动化测试

JMS and ActiveMQ first lesson(转)

JMS and ActiveMQ first lesson -- jms基础概念和应用场景 2011-6-18 PM 9:30 主讲:kimmking <[email protected]> 整理:林木森 ppt下载地址: http://code.google.com/p/activemq-store-mongodb/downloads/list 下面开始: kimmking:介绍下jms和ActiveMQ.在讲JMS之前,我们聊聊相关的背景.谁知道JMS是什么意思? kimmking:对,是

the solution of CountNonDivisible by Codility

question:https://codility.com/programmers/lessons/9 To solve this question , I get each element's divsors which appearing in input Array A using Sieve of Eratosthenes method. Time complexity is O(nlogn); Then  we iterate array A to get the ith non-di

Solution of NumberOfDiscIntersections by Codility

question:https://codility.com/programmers/lessons/4 trap: int overflow code: #include <algorithm> int solution(vector<int> &A) { // write your code in C++11 int size = A.size(); if (size <2) return 0; vector<long> begin; vector<

GenomicRangeQuery /codility/ preFix sums

首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides of types A,

新概念 第一册 lesson 59~60

lesson thirteen Is that all? 1.Review What's the time? It's *** o'clock.    It's ten a.m. It's four p.m. 方式状语: by bus/car/bike on foot 句型: They usually...but today,they... 他们通常都干...事情但今天,他们... e.g. They usually go to school by bus,but today,they are

codility上的问题(34) Fluorum 2014

好久没写codility的题了,一来没时间,二来有的题目不太好分析.这个题比较有意思,我还没有给出非常严格的证明. 给定一棵树(无向无环图),从一个节点出发,每次选择一个节点,从起点到目的节点的路径上没经过的节点尽可能多,直到遍历完所有的节点.如果起点到两个目的节点的路径中没经过的节点同样多,则选择标号较小的节点作为目的节点.如此继续,直到遍历所有的节点,求按顺序选择了哪些目的节点? 例如从2 开始,第一次选择0,然后1,0变为经历过的节点. 然后从0开始,第二次选择6, 然后4,6变为经历过的