zoukankan      html  css  js  c++  java
  • LeetCode Contest 180

    第一题

    class Solution {
    public:
        vector<int> luckyNumbers (vector<vector<int>>& matrix) {
            
            vector<int> ans;
            
            vector<int> n;
            for(int i=0;i<matrix.size();i++)
            {
                int x=INT_MAX;
                for(int j=0;j<matrix[i].size();j++)
                {
                    x=min(x,matrix[i][j]);
                }
                n.push_back(x);
            }
            
            vector<int> m;
            for(int i=0;i<matrix[0].size();i++)
            {
                int x =-1;
                for(int j=0;j<matrix.size();j++)
                {
                    x=max(x,matrix[j][i]);
                }
                m.push_back(x);
            }
            
            for(int i=0;i<n.size();i++)
            {
                for(int j=0;j<m.size();j++)
                {
                    if(n[i]==m[j])
                        ans.push_back(n[i]);
                }
            }
            
            return ans;
            
        }
    };
    

    第二题

    class CustomStack {
    public:
        int s[1005];
        int m;
        int top;
        CustomStack(int maxSize) {
            m=maxSize;
            top=0;
        }
        
        void push(int x) {
            if(top<m)
             s[top++]=x;
        }
        
        int pop() {
            
            if(top==0)
                return -1;
            int x=s[top-1];
            top--;
            return x;
            
        }
        
        void increment(int k, int val) {
            
            for(int i=0;i<k&&i<top;i++)
            {
                s[i]+=val;
            }
        }
    };
    
    /**
     * Your CustomStack object will be instantiated and called as such:
     * CustomStack* obj = new CustomStack(maxSize);
     * obj->push(x);
     * int param_2 = obj->pop();
     * obj->increment(k,val);
     */
    

    第三题

    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
    class Solution {
    public:
        vector<int> nums;
        TreeNode* balanceBST(TreeNode* root) {
            
            fun(root);
            TreeNode* node;
            build(node,0,nums.size()-1);
            return node;
        }
        
        void build(TreeNode* &root,int l,int r)
        {
            int mid = (l+r)/2;
            int x = nums[mid];
            root = new TreeNode(x);
            if(l<=mid-1)
                build(root->left,l,mid-1);
            if(mid+1<=r)
                build(root->right,mid+1,r);
        }
        
        void fun(TreeNode* root)
        {
            if(root!=NULL)
            {
                fun(root->left);
                nums.push_back(root->val);
                fun(root->right);
            }
        }
        
    };
    

    第四题

    typedef long long int _int;
    
    struct Node
    {
        int effic;
        int speed;
    }a[100005];
    int cmp(Node a,Node b)
    {
        if(a.effic==b.effic)
            return a.speed>b.speed;
        return a.effic<b.effic;
    }
    class Solution {
    public:
        priority_queue<int, vector<int>, greater<int>> q;
        _int value =  1000000000 + 7;
        int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {
    
            for(int i=0;i<n;i++)
            {
                a[i].speed = speed[i];
                a[i].effic = efficiency[i];
            }
    
            sort(a,a+n,cmp);
    
            _int ans=0;
            _int x;
            _int y=0;
            for(int i=n-1;i>=0;i--)
            {
                ans=max(ans,a[i].effic*(y+a[i].speed));
                q.push(a[i].speed);
                y+=a[i].speed;
                if(q.size()>k-1)
                {
                    y-=q.top();
                    q.pop();
                }
            }
    
            return ans%value;
    
        }
    };
    
    
  • 相关阅读:
    mysql INNODB_TRX 事务表
    14.4.5 System Tablespace 系统表空间
    14.4.4 Redo Log Buffer
    14.4.3 Adaptive Hash Index 自适应hash index
    14.4.2 Change Buffer 延迟写
    14.4.1 Buffer Pool
    14.3 InnoDB Multi-Versioning InnoDB 多版本
    14.2 InnoDB and the ACID Model
    14.1.3 检查InnoDB 可用性:
    算法分类(写这个是为了让自己以后学算法的时候有针对性条理性)
  • 原文地址:https://www.cnblogs.com/dacc123/p/12497195.html
Copyright © 2011-2022 走看看