兰聪


私信TA

用户名:dotcpp0606174

访问量:914

签 名:

等  级
排  名 2827
经  验 2060
参赛次数 0
文章发表 13
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

TA的其他文章

    这题可以直接用类似于滑动窗口的思想来做

参考代码:

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class T2911 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str = sc.next();
		
		int cnt = 0;
		int index = 0;
		
		LinkedList<Character> result = new LinkedList<>();
		
		for (int i = 0; i < str.length(); i++) {
			result.add(str.charAt(i));
			cnt++;
			
			while(!f(result)) {
				result.removeFirst();
				cnt--;
			}
			
			if(cnt == n) {
				index = i;
				break;
			}
		}
		
		if(cnt != n) {
			System.out.println("No");
		}else {
			System.out.println(result.getFirst());
		}
	}
	
	public static boolean f(LinkedList<Character> result) {
		
		Set<Character> set = new HashSet<>(result);
		
		if(set.size() == 1) {
			return true;
		}
		
		return false;
	}

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区