牛客编程巅峰赛钻石王者组第五场

牛客编程巅峰赛钻石王者组第五场

链接说明
我好菜啊,第三题完全没思路。

1. 滑动窗口双指针

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     * 返回符合题意的最长的子串长度
     * @param x string字符串 
     * @return int整型
     */
    public int Maximumlength (String x) {

        // write code here
        int n = 0;
        int p = 0;
        int y = 0;
        int l = 0;
        int r = 0;
        char[] chars = x.toCharArray();
        int len = chars.length;
        int maxLen = 0;
        while(r < len){
            char chr = chars[r];
            if(chr == 'n'){++n;}
            if(chr == 'p'){++p;}
            if(chr == 'y'){++y;}
            while(n * p * y != 0){
                if(chars[l] == 'n'){--n;}
                if(chars[l] == 'p'){--p;}
                if(chars[l] == 'y'){--y;}
                ++l;
            }
            maxLen = Math.max(maxLen, r - l + 1);
            ++r;
        }
        return maxLen;
    }
}

2. 后缀表达式求值

使用栈模拟:

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     * 给定一个后缀表达式,返回它的结果
     * @param str string字符串 
     * @return long长整型
     */
    public long solve (String str) {
        // write code here
        long res = 0;
        char[] chars = str.toCharArray();
        int len = chars.length;
        Deque<Long> stack = new ArrayDeque<>();
        long num = 0;
        for(int i = 0; i < len; ++i){
            char ch = chars[i];
            if(ch >= '0' && ch <= '9'){
                num = num * 10 + ch - '0';
            }else if(ch == '#'){
                stack.push(num);
                num = 0;
            }else{
                long a = stack.pop();
                long b = stack.pop();
                if(ch == '+'){
                    stack.push(a + b);
                }else if(ch == '-'){
                    stack.push(b - a);
                }else if(ch == '*'){
                    stack.push(a * b);
                }
            }
        }
        return stack.pop();
    }
}
#笔试题目#
全部评论
自顶向下,帮我点个赞吧,**的我做出两题不容易
1 回复 分享
发布于 2020-12-01 22:27

相关推荐

投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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