欧美1区2区3区激情无套,两个女人互添下身视频在线观看,久久av无码精品人妻系列,久久精品噜噜噜成人,末发育娇小性色xxxx

題解 | #四數(shù)之和#

四數(shù)之和

http://www.fangfengwang8.cn/practice/d5b74806fa104518903884e182f47e35

class Solution {
  public:
    /**
     * 代碼中的類名、方法名、參數(shù)名已經(jīng)指定,請勿修改,直接返回方法規(guī)定的值即可
     *
     *
     * @param nums int整型vector
     * @param target int整型
     * @return int整型vector<vector<>>
     */
    vector<vector<int> > fournumber(vector<int>& nums, int target) {
        // write code here
        std::vector<std::vector<int>> result;
        if (nums.size() < 4) return result;

        std::sort(nums.begin(), nums.end());

        for (int i = 0; i < nums.size() - 3; ++i) {
            if (i > 0 &&
                    nums[i] == nums[i - 1]) continue;  // Skip duplicates for the first number

            for (int j = i + 1; j < nums.size() - 2; ++j) {
                if (j > i + 1 &&
                        nums[j] == nums[j - 1]) continue;  // Skip duplicates for the second number

                int left = j + 1;
                int right = nums.size() - 1;

                while (left < right) {
                    long long sum = (long long)nums[i] + nums[j] + nums[left] + nums[right];
                    if (sum == target) {
                        result.push_back({nums[i], nums[j], nums[left], nums[right]});
                        while (left < right &&
                                nums[left] == nums[left + 1]) ++left;  // Skip duplicates for the third number
                        while (left < right &&
                                nums[right] == nums[right - 1]) --right;  // Skip duplicates for the fourth number
                        ++left;
                        --right;
                    } else if (sum < target) {
                        ++left;
                    } else {
                        --right;
                    }
                }
            }
        }

        return result;
    }
};

全部評論

相關(guān)推薦

你背過凌晨4點的八股文么:加油同學(xué),人生的容錯率很高,只是一個暑期罷了,后面還有很多機會!
點贊 評論 收藏
分享
評論
點贊
收藏
分享

創(chuàng)作者周榜

更多
??途W(wǎng)
??推髽I(yè)服務(wù)