2021/8/27

三题leetcode

背Mysql的八股文

写测评

学习mysql 5讲

class Solution {
public:
    long long get_count(long long p1,long long n){
        long long  ans = 0;
        for(long long p = p1,q = p + 1; p <= n;p *= 10,q = q * 10){
            ans += min(q,n + 1) - p;
        }
        return ans;
    }
    int findKthNumber(int n, int k) {
        int ans = 0;
        int p = 1;
        int cnt = 1;
        while(cnt < k){
            int t = get_count(p,n);
            if(cnt + t > k){
                p = p * 10;
                ++ cnt;
            } else {
                ++ p;
                cnt += t;
            }
        }
        return p;
    }
};

  

class Solution {
public:
    int dp[220][220]= {0};
    int n,m;
    int check(int x,int y){
        if(x < 0 || y < 0 || x >= n || y >= m) return 0;
        return 1;
    }
    int dirx[4] = {-1,0,1,0};
    int diry[4] = {0,1,0,-1};
    int dfs(int x,int y,vector<vector<int>>& matrix){
        if(check(x,y) == 0) return 0;
        if(dp[x][y]) return dp[x][y];
        int ans = 1;
        for(int i = 0; i < 4; i ++){
            int X = x + dirx[i]; 
            int Y = y + diry[i];
            if(check(X,Y) == 0) continue;
            if(matrix[X][Y] > matrix[x][y] && check(X,Y)){
                ans = max(ans,dfs(X,Y,matrix) + 1);
            }
        }
        dp[x][y] = max(dp[x][y],ans);
        return dp[x][y];
    }
    int longestIncreasingPath(vector<vector<int>>& matrix) {
        n = matrix.size(); m = matrix[0].size();
        int maxx = 0;
        for(int i = 0; i < matrix.size(); i ++){
            for(int j = 0; j < matrix[i].size(); j ++){
                if(dp[i][j] == 0){
                    dp[i][j] = dfs(i,j,matrix);
                    maxx = max(maxx,dp[i][j]);
                } else maxx = max(maxx,dp[i][j]);
            }
        }
     
        return maxx;
    }
};

  

posted @ 2021-08-27 22:31  风生  阅读(27)  评论(0编辑  收藏  举报