当前位置:网站首页>[12. maximum continuous non repeating subsequence]
[12. maximum continuous non repeating subsequence]
2022-06-27 07:51:00 【Little silly bird_ coding】
Two cases of double pointer algorithm

#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;
int main()
{
char str [1000];
//scanf("%s", str);
fgets(str,sizeof(str), stdin);
int n = strlen(str);
for (int i = 0; i < n; i ++)
{
int j = i;
while (j < n && str[j] != ' ') j ++;
// The specific logic of this problem
for (int k = i; k < j; k ++) cout << str[k];
cout << endl;
i = j;
}
return 0;
}
Running results :
Input :
abc def cde
Output :
abc
def
cde
Maximum continuous unrepeated subsequence

- Open up an additional array S[N], Record dynamically , How many times does the element appear , amount to i Move back one space at a time , Just go S[N] Add an element to , If j Move one space forward , It is equivalent to repeated numbers , In from S[N] Delete the element from .
- Finally, we can make dynamic statistics , How many numbers are there in this array
Given a length of n Integer sequence of , Please find the longest continuous interval that does not contain repeated numbers , Output its length .
subject
Given a length of n Integer sequence of , Please find the longest continuous interval that does not contain repeated numbers , Output its length .
Input format
The first line contains integers n.
The second line contains n It's an integer ( Both in 0∼100000 Within the scope of ), Represents a sequence of integers .
Output format
All in one line , Contains an integer , Represents the length of the longest continuous interval without repetition .
Data range
1 ≤ n ≤ 100000
sample input :
5 1 2 2 3 5sample output :
3
Code
#include<iostream> using namespace std; const int N = 100010; int n; int a[N],s[N]; int main() { cin >> n; for (int i = 0; i < n; i ++) cin >> a[i]; int res = 0; for (int i = 0, j = 0; i < n; i ++) { s[a[i]] ++; while (s[a[i]] > 1) { s[a[j]] --; j ++; } res = max(res, i - j + 1); } cout << res << endl; return 0; }
边栏推荐
- 若xn>0,且x(n+1)/xn>1-1/n(n=1,2,...),证明级数∑xn发散
- 野風藥業IPO被終止:曾擬募資5.4億 實控人俞蘠曾進行P2P投資
- Sword finger offer 07 Rebuild binary tree
- Speech signal feature extraction process: input speech signal - framing, pre emphasis, windowing, fft- > STFT spectrum (including amplitude and phase) - square the complex number - > amplitude spectru
- R language consumption behavior statistics based on association rules and cluster analysis
- 什么是期货反向跟单?
- 淘宝虚拟产品开店教程之作图篇
- JDBC读取Mysql数据列表
- 认识O(NlogN)的排序
- js用while循环计算假如投资多年的利率为5%,试求从1000块增长到5000块,需要花费多少年
猜你喜欢

L'enquête en aveugle a montré que les femmes étaient meilleures que les hommes.

磁选机是什么?

Remote connection raspberry pie in VNC Viewer Mode
![log4j:WARN No such property [zipPermission] in org.apache.log4j.RollingFileAppender.](/img/2c/425993cef31dd4c786f9cc5ff081ef.png)
log4j:WARN No such property [zipPermission] in org.apache.log4j.RollingFileAppender.

基础知识 | js基础

八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
![[compilation principles] review outline of compilation principles of Shandong University](/img/a6/b522a728ff21085411e7452f95872a.png)
[compilation principles] review outline of compilation principles of Shandong University
![[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment](/img/ac/44e0ecd04fbea5efd39d2cc75dea59.jpg)
[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment

【批处理DOS-CMD命令-汇总和小结】-将文件夹映射成虚拟磁盘——subst

js用while循环计算假如投资多年的利率为5%,试求从1000块增长到5000块,需要花费多少年
随机推荐
[compilation principles] review outline of compilation principles of Shandong University
PostgreSQL encounters permission denied in Windows system
js例题打印1-100之间所有7的倍数的个数及总和
Win10 how to manage startup items?
How can I import data from Oracle into fastdfs?
JS to determine whether the number entered by the user is a prime number (multiple methods)
Remote connection raspberry pie in VNC Viewer Mode
Speech synthesis: tacotron explains [end-to-end speech synthesis model] [compared with traditional speech synthesis, it does not have complex phonetics and acoustic feature modules, but only uses < te
05 观察者(Observer)模式
JS find the number of all daffodils
2022 love analysis · panoramic report of it operation and maintenance manufacturers
淘宝虚拟产品开店教程之作图篇
【批处理DOS-CMD命令-汇总和小结】-输出/显示命令——echo
Closure problem
js成绩奖惩例题
Online text digit recognition list summation tool
After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness
盲测调查显示女码农比男码农更优秀
Mobile security tools -jad
二叉树结构以及堆结构基础