头像

xiaosuo


访客:137

离线:17小时前


活动打卡代码 LeetCode 56. 合并区间

xiaosuo
5天前
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<vector<int>> res;
        if(!intervals.size()) return res;
        sort(intervals.begin(),intervals.end());

        int l = intervals[0][0],r = intervals[0][1];
        for(int i = 0; i < intervals.size(); i++){
            if(intervals[i][0] > r){
                res.push_back({l,r});
                l = intervals[i][0],r = intervals[i][1];
            }
            else{
                r = max(r,intervals[i][1]);
            }
        }

        res.push_back({l,r});
        return res;
    }
};



xiaosuo
10天前

想问一下大家,刷题一般都是只考算法,没有完整的main函数,要是准备笔试的话需要写完整的程序,怎么针对这一点刷一下题呢



活动打卡代码 LeetCode 35. 搜索插入位置

xiaosuo
13天前
class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int l = 0,r = nums.size();

        while(l<r){
            int mid = (l+r)/2;
            if(nums[mid]<target) l = mid + 1;
            else r = mid;
        }
        return l;
    }
};



xiaosuo
13天前
class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.empty()) return {-1,-1};

        int l = 0,r  =nums.size() - 1;
        while(l<r){
            int mid = (l+r)/2;
            if(nums[mid] >= target) r = mid;
            else l = mid+1;
        }
        if(nums[l] != target) return {-1,-1};
        int L = l;

        l = 0,r = nums.size() - 1;
        while(l<r){
            int mid = (l+r+1)/2;
            if(nums[mid]>target) r = mid - 1;
            else l = mid;
        }
        return {L,r};
    }
};



xiaosuo
13天前
class Solution {
public:
    int search(vector<int>& nums, int target) {
        if(nums.empty()) return -1;

        int l = 0,r = nums.size() - 1;
        while(l<r){
            int mid = (l + r + 1)/2;
            if(nums[mid]>=nums[0]) l = mid;
            else r = mid - 1;
        }
        if(target>=nums[0]) l = 0;
        else l = l + 1,r = nums.size() - 1;

        while(l<r){
            int mid = (l+r)/2;
            if(nums[mid] >= target) r = mid;
            else l = mid + 1;
        }
        if(nums[r] == target) return r;
        else return -1;
    }
};


活动打卡代码 LeetCode 27. 移除元素

xiaosuo
14天前
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int k = 0;
        for(int i =0;i<nums.size();i++){
            if(nums[i] != val){
                nums[k] = nums[i];
                k++;
            }
        }
        return k;
    }
};



xiaosuo
14天前
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int k = 0;
        for(int i = 0;i<nums.size();i++){
            if(!i || nums[i] !=nums[i-1]){
                nums[k] = nums[i];
                k++;
            }

        }
        return k;
    }
};


活动打卡代码 LeetCode 14. 最长公共前缀

xiaosuo
21天前
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string s;
        if(strs.size() == 0 ) return s;
        int minlen = strs[0].size();
        for(int i = 1;i<strs.size();i++){
            if(strs[i].size() < minlen ){
                minlen = strs[i].size();
            }
        }
        for(int i = 0;i < minlen;i++){
            char ch = strs[0][i];
            for(int j = 1;j<strs.size();j++){
                if(ch != strs[j][i]){
                    return s;
                }
            }
            s += ch;
        }
        return s;
    }
};



xiaosuo
21天前
class Solution {
public:
    int maxArea(vector<int>& height) {
        int l = 0,r = height.size() - 1;
        int ans = 0;
        while(l<r){
            int area = min(height[l],height[r])*(r-l);
            ans = max(area,ans);
            if(height[l]<=height[r]){
                l++;
            }
            else{
                r--;
            }
        }
        return ans;
    }
};


活动打卡代码 AcWing 1. A + B

xiaosuo
1个月前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

include[HTML_REMOVED]

using namespace std;

int main(){
int a,b;
cin>>a>>b;
cout<<a+b<<endl;

}