当前位置: 首页> 健康> 美食 > 高端网咖_开发公司垫付拆迁款后未取得土地纠纷_在线培训网站次要关键词_百度一下官方入口

高端网咖_开发公司垫付拆迁款后未取得土地纠纷_在线培训网站次要关键词_百度一下官方入口

时间:2025/7/12 7:32:18来源:https://blog.csdn.net/blamep/article/details/143696609 浏览次数:0次
高端网咖_开发公司垫付拆迁款后未取得土地纠纷_在线培训网站次要关键词_百度一下官方入口

1.牛牛冲钻五

题目链接:A-牛牛冲钻五_牛客小白月赛38

题目描述:

代码如下:

import java.util.*;public class Main{public static void main(String[] args){Scanner scanner=new Scanner(System.in);int t=scanner.nextInt();while(t--!=0){int n=scanner.nextInt();int k=scanner.nextInt();int ret=0;char[] s=scanner.next().toCharArray();for(int i=0;i<s.length;i++){if(s[i]== 'L'){ret-=1;}else{if(i-1>=0 && i-2>=0 && s[i-1]=='W' && s[i-2]=='W'){ret+=k;}else{ret+=1;}}}System.out.println(ret);}}}

2.最长无重复子数组

题目链接:最长无重复子数组_牛客题霸_牛客网 

题目描述:

判断是否是重复的话,可以使用哈希表,但是要注意时间复杂度 

代码如下:

import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** * @param arr int整型一维数组 the array* @return int整型*/public int maxLength (int[] arr) {int ret=0;int[] hash=new int[100010];int right =0;int left=0;while(right<arr.length){hash[arr[right]]++;while(hash[arr[right]]>1){hash[arr[left]]--;left++;}ret=Math.max(ret,right-left+1);right++;}return ret;}
}

3.小红的字符串重排

注:如果相同字母的个数大于总数的一半,则不满足条件。

代码如下:

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();char[] s = scanner.next().toCharArray();scanner.close();char maxChar = '0';int maxCount = 0;int[] hash = new int[26];for (int i = 0; i < s.length; i++) {char ch = s[i];hash[ch - 'a']++;if (hash[ch - 'a'] > maxCount) {maxChar = ch;maxCount = hash[ch - 'a'];}}if (maxCount > (n + 1) / 2) {System.out.println("no");} else {System.out.println("yes");char[] ret = new char[n];int i = 0;// 先填充最多的字符while (maxCount-- > 0) {ret[i] = maxChar;i += 2;}// 填充其他字符for (int j = 0; j < 26; j++) {if (hash[j] > 0 && (char) (j + 'a') != maxChar) {while (hash[j]-- > 0) {if (i >= n) i = 1; // 如果偶数位填满,从奇数位开始ret[i] = (char) (j + 'a');i += 2;}}}// 输出结果System.out.println(new String(ret));}}
}

希望能对大家有所帮助!!! 

关键字:高端网咖_开发公司垫付拆迁款后未取得土地纠纷_在线培训网站次要关键词_百度一下官方入口

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: