牛牛算数

牛牛算数

https://ac.nowcoder.com/acm/contest/9556/A

链接:https://ac.nowcoder.com/acm/contest/9556/A
来源:牛客网

给你一个含有n个元素的数组arr[i],请你告诉牛牛这个数组的中位数大还是平均数大,如果中位数更大输出1,如果平均数更大输出-1,如果中位数和平均数相等输出0

要先Arrays.sort()才行

import java.util.*;

public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 返回符合题意的最长的子串长度
* @param x string字符串
* @return int整型
*/
public int Maximumlength (String x) {
// write code here
int n = -1,p = -1,y = -1;
int cur = 0,max = 0;
for(int i = 0;i < x.length();i++){
char c = x.charAt(i);
if(c == 'n')n = i;
if(c == 'p')p = i;
if(c == 'y')y = i;

        if(n == -1 || p == -1 || y == -1){
            cur++;
            max = max > cur ? max : cur;

        }else{
            int last = -1;
            if(n < p)last = n;
            else last = p;
            if(y < last)last = y;
            cur = i - last;
            max = max > cur ? max : cur;

        }


    }
    return max;


}

}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务