C++笔试题

还是太菜了,好好努力吧✊🏻

正则表达式

匹配邮箱

哈希冲突的解决方法

开放地址法(再散列法)、拉链法、再哈希法、建立公共溢出区

十大排序算法中的稳定排序

冒泡排序、插入排序、归并排序

实现TCP网络应用程序,服务器端正确的处理流程

socket() -> bind() -> listen() ->accpet() -> read() ->write() ->read() -> close()

力扣91题解码https://leetcode-cn.com/problems/decode-ways/

class Solution {
public:
    int numDecodings(string s) {
        if(s[0] == '0')
            return 0;
        int size = s.size();
        int a = 1, b = 1, c = 0;
        for(int i = 1; i < size; i++)
        {
            c = b;
            if(s[i] == '0') //i位为0
            {
                if(s[i - 1] == '1' || s[i - 1] == '2') //看看能不能从前面找个凑
                {
                    b = a;
                }    
                else
                {
                    return 0;
                }  
            }
            else if(s[i-1] == '1'|| (s[i-1] == '2' && s[i] >= '1' && s[i] <= '6')) //只能是单独组成一个 s[i-1]=2 s[i]范围为1-6 
            { 
                 b = b + a; 
            }
            a = c;
            
        }
        return b;
    }
};

力扣28.实现strstr() 考KMP算法https://leetcode-cn.com/problems/implement-strstr/

class Solution {
public:
    int strStr(string haystack, string needle) {
        int n = haystack.size();
        int m = needle.size();
        if(m == 0)
            return 0;
        //第一位设置为哨兵,字符串全部往后推进一位
        haystack.insert(haystack.begin(), ' ');
        needle.insert(needle.begin(), ' ');
        vector<int>  next(m+1);
        //预处理next数组
        for(int i = 2, j = 0; i <= m; i++){
            while(j and needle[i] != needle[j + 1]) 
                j = next[j];
            if(needle[i] == needle[j + 1]) 
                j++;
            next[i] = j;
        }
        //匹配过程
        for(int i = 1,j = 0; i <= n; i++)
        {
            while(j and haystack[i] != needle[j + 1])
                j = next[j];
            if(haystack[i] == needle[j + 1])
                j++;
            if(j == m)
                return i - m;
        }
        return -1;
    }
};

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值