hiho一下 第229周:Same Letters In A Row
分析:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
string s;
int k;
int a[30];
bool Judge(int i,int j,int k)
{
int tmp=j-i+1;
int res=0;
for(int ii=0;ii<26;ii++)
{
int num=0;
if(a[ii]>=tmp){
for(int kk=i;kk<=j;kk++)
{
if(s[kk]-'a'!=ii)
num++;
}
if(num<=k)
return true;
}
}
return false;
}
void solve(int n)
{
memset(a, 0, sizeof(a));
int len=s.size();
for(int i=0;i<len;i++)
{
a[s[i]-'a']++;
}
int i=0;
int j=1;
int res=0;
while (i<len&&j<len)
{
if(Judge(i, j, n)==true)
{
res=max(res,j-i+1);
j++;
}
else
{
i++;
}
}
cout<<res<<endl;
}
int main()
{
while (~scanf("%d",&k))
{
cin>>s;
solve(k);
}
return 0;
}
相關文章
- hiho一下 第230周 Smallest Substring
- [LintCode/LeetCode] Remove Duplicate LettersLeetCodeREM
- 100. Same Tree
- [leetcode]same-treeLeetCode
- 100-Same Tree
- Remove Duplicate Letters 刪除重複元素REM
- Leetcode 100. Same TreeLeetCode
- B. Same Parity Summands
- MySQL裡的found_row()與row_count()MySql
- A. Arrow a Row
- ORACLE ROW MOVEMENTOracle
- The fundamental idea remains the same as previous yearsIdeaREMAI
- c++11:std::is_sameC++
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- MySQL Binlogging Fails With Writing One Row To The Row-based Binary Log FailedMySqlAI
- Different AG groups have the exactly same group_id value if the group names are same and the ‘CLUSTER_TYPE = EXTERNAL/NONE’None
- 第134期 勘誤且自嘲一下(20240115)
- #1118 - Row size too large. The maximum row size for the used table type, not counting BLOBs
- LeetCode C++ 316. Remove Duplicate Letters【Stack/Greedy/String】中等LeetCodeC++REM
- enq: TX - row lock contentionENQ
- [Javascript] Import the Same JavaScript Module Multiple Times with Cache BustingJavaScriptImport
- [20190706]Same dog, different leash – functions in SQL.txtFunctionSQL
- Flutter 之 Row、Column詳解Flutter
- flutter佈局-2-rowFlutter
- 623-Add One Row to Tree
- Same Origin Policy 瀏覽器同源策略詳解瀏覽器
- MySQL8.0 binlog_row_metadataMySql
- Oracle vs PostgreSQL Develop(19) - PIPE ROWOracleSQLdev
- 等待事件enq: TX - row lock contention事件ENQ
- PostgreSQL DBA(102) - pgAdmin(Row Level Security)SQL
- InnoDB從內分析之Row(一)
- Flutter基礎元件Row&ColumnFlutter元件
- Flutter之Row/Column用法詳解Flutter
- Oracle中rownum和row_number()Oracle
- Flutter線性佈局Row和ColumnFlutter
- Hive ROW_NUMBER,RANK(),DENSE_RANK()Hive
- Flutter控制元件--Row、Column和StackFlutter控制元件
- sql中row_number over語句SQL