算法学习

算法解释:

KMP算法(字符串查找算法),BM算法,Sunday算法:https://blog.csdn.net/liu940204/article/details/51318281

十大排序算法:https://www.cnblogs.com/onepixel/articles/7674659.html?tdsourcetag=s_pctim_aiomsg

leetcode刷题:

53.最大子序列和

      https://blog.csdn.net/zwzsdy/article/details/80029796(四种方法)

169.求众数

       https://blog.csdn.net/Oscar6280868/article/details/84062124(摩尔投票法)

       https://blog.csdn.net/qq_41231926/article/details/86479848(五种方法,包括分治,摩尔投票,位运算)'

420.强密码检验(这个感觉没什么算法,就是逻辑能力?)

       https://blog.csdn.net/qq_28453735/article/details/76762246

39.组合总和(回溯算法,递归实现)

      https://blog.csdn.net/qq_17550379/article/details/82561538

      我的代码:

class Solution {
public:
    vector> combinationSum(vector& candidates, int target) {
        sort(candidates.begin(),candidates.end());
        vector> result;
        vector one;
        comb(candidates,target,0,one,result);
        return result;
    }
    void comb(vector& can,int target,int index, vector& one,vector>& result){
        if(target==0){
            result.push_back(one);
            return;
        }
        if(target<0){
            return;
        }
        for(int i=index;i

62.不同路径(动态规划及优化)

      https://blog.csdn.net/xushiyu1996818/article/details/86308900

      https://segmentfault.com/a/1190000016315625

      动态规划代码:

class Solution {
public:
    int uniquePaths(int m, int n) {
        int dp[m][n];
        for(int i=0;i

优化:

class Solution {
public:
    int uniquePaths(int m, int n) {
        if(m<=0||n<=0){
            return 0;
        }
        int dp[n];
        for(int i=0;i

63.不同路径2

     在前一题的动态规划基础上加一些判断,但是存在一个整数溢出的问题,改成long,long long也没有用

3.无重复字符的最长字串

1.暴力解法:

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        
        int length = 0;
        for(int i=0;ilength){
                length = news.length();
            }
            
        }
        return length;
    }
};

2.滑动窗口

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        string news = "";
        int length = 0;
        int left = -1;
        for(int i=0;ileft?loc:left;
                cout<length){
                length = i-left;
            } 
        }
        return length;
    }
};

3.评论中看到的一个

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int  size,i=0,j,k,max=0;
        size = s.size();
        for(j = 0;j max)
                max = j-i+1;
        }
        return max;
    }
};

 

你可能感兴趣的:(算法)