From 7ce65aead5a1b53deab33fb26878da6a0ad9525d Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Tue, 8 Feb 2022 10:41:58 +0800 Subject: [PATCH] =?UTF-8?q?799.=20=E6=9C=80=E9=95=BF=E8=BF=9E=E7=BB=AD?= =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=A4=8D=E5=AD=90=E5=BA=8F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/10688919/ --- AcWing/799/799.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 AcWing/799/799.cpp diff --git a/AcWing/799/799.cpp b/AcWing/799/799.cpp new file mode 100644 index 00000000..09b207a4 --- /dev/null +++ b/AcWing/799/799.cpp @@ -0,0 +1,21 @@ +#include + +using std::cin; +using std::cout; +#define endl '\n' + +int n, a[100005], s[100005], ans; + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + for (int i = 1, j = 1; i <= n; i++) { + s[a[i]]++; + while (s[a[i]] > 1) s[a[j++]]--; + ans = std::max(ans, i - j + 1); + } + cout << ans << endl; + return 0; +}