Bîn-hiân ê 演算法練習
作品集贊助支持
2024年2月10日

FrogRiverOne

codility

https://app.codility.com/programmers/lessons/4-counting_elements/frog_river_one/

#include <bits/stdc++.h>

using namespace std;

int solution(int X, vector<int> &A)
{
    set<int> st;
    int n = A.size();
    for (int i = 0; i < n; ++i)
    {
        st.insert(A[i]);
        if (st.size() == X)
        {
            return i;
        }
    }
    return -1;
}
  • T: O()O()O()
  • S: O()O()O()

Copyright © 2026 Bîn-hiân