***Leetcode 881. Boats to Save People

Posted Z-Pilgrim

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了***Leetcode 881. Boats to Save People相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/boats-to-save-people/description/

 

赤裸裸的双指针的题,,竟然没看出来。。。

class Solution 
public:
    int numRescueBoats(vector<int>& people, int limit) 
        sort(people.begin(), people.end());
        int i = 0, j = people.size() - 1;
        int ret = 0;
        while (i <= j) 
            // cout << "i:" << i << " j:" << j << endl;
            if (people[j] + people[i] <= limit) 
                i ++, j--;
             else 
                j--;
            
            ret ++;
        
        return ret;
    
;

 

 

以上是关于***Leetcode 881. Boats to Save People的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] 881. Boats to Save People

[LeetCode] Boats to Save People 渡人的船

Foreigners can paddle dragon boats to Duanwu Festival

LeetCode:救生艇881

LeetCode 881 救生艇(贪心)

LeetCode 881. 救生艇